1

how to replace this query in sql server ?

DELETE FROM student 
WHERE id=2 
 AND list_column_name='lastName' 
  OR list_column_name='firstName' 
LIMIT 3;
2
  • You are trying to delete no more than 3 records, that match the WHERE clause? Commented Dec 18, 2015 at 11:55
  • 2
    You have not even provided an ORDER BY. Commented Dec 18, 2015 at 11:56

2 Answers 2

2

There is no ORDER BY in your original query.

If you just want to delete an arbitary three records matching your WHERE you can use.

DELETE TOP(3) FROM student
WHERE  id = 2
       AND list_column_name = 'lastName'
        OR list_column_name = 'firstName';

For greater control of TOP (as ordered by what?) you need to use a CTE or similar.

Sign up to request clarification or add additional context in comments.

Comments

1

using CTE and TOP 3 where equal to LIMIT 3

;WITH CTE
     AS (SELECT TOP 3 Studentname
         FROM   student
         WHERE  id = 2
                AND list_column_name = 'lastName'
                 OR list_column_name = 'firstName')
DELETE FROM CTE 

3 Comments

CTE its not excepting, does CTE means column name
can you tell me in which environment you are executing ?
You were missing a column list between TOP 3 and FROM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.