Nick T
Nick T

Reputation: 683

Using AND in a DELETE FROM statement

I'm having trouble using the AND operator in a DELETE FROM statement. I can get the query to run successfully, but it's not affecting any rows. If I edit the query, get rid of the AND operator and its conditional, it will run successfully and delete that one row. Here's the example I'm working with.

DELETE FROM classicmodels.employees 
WHERE
    employeeNumber = 1706
    AND employeeNumber = 1707

Why is my query not deleting the rows? How would I fix this? I appreciate any help with this.

Upvotes: 0

Views: 359

Answers (2)

Rajat
Rajat

Reputation: 5793

You must have meant OR

DELETE 
FROM classicmodels.employees 
WHERE employeeNumber = 1706 OR employeeNumber = 1707;

Can also be written as

DELETE 
FROM classicmodels.employees 
WHERE employeeNumber IN (1706,1707)

Upvotes: 1

Barmar
Barmar

Reputation: 781708

AND means a row has to satisfy both conditions (think about how you use it when matching different columns). It's not possible for the row to have two different employeeNumber values.

If you want to delete both employees, you should use OR, not AND.

Even better is to use IN: WHERE employeeNumber IN (106, 107)

Upvotes: 2

Related Questions