user4756836 user4756836 - 7 months ago 14
SQL Question

Remove all rows Except condition

I would like to remove all rows from the table EXCEPT when

FirstName
is Ben and
isAdmin
is true

Here is my SQL

DELETE FROM Table1
WHERE (FirstName <> 'Ben' AND isAdmin = 1);


However, my issue is that when
isAdmin
is false... it should remove that row as well but it doesn't remove it. What is my issue here?

Answer

The correct SQL should be

DELETE FROM Table1
WHERE (FirstName <> 'Ben' OR isAdmin = 0);