SQL WHERE condition is not equal to?

前端 未结 10 1890
一生所求
一生所求 2020-12-07 21:48

Is it possible to negate a where clause?

e.g.

DELETE * FROM table WHERE id != 2;
10条回答
  •  天涯浪人
    2020-12-07 22:09

    Your question was already answered by the other posters, I'd just like to point out that

     delete from table where id <> 2
    

    (or variants thereof, not id = 2 etc) will not delete rows where id is NULL.

    If you also want to delete rows with id = NULL:

    delete from table where id <> 2 or id is NULL
    

提交回复
热议问题