mysql中where语句的不等于操作

2022-10-12 13:39:21

mysql中where语句的不等于操作

众所周知,我们在使用多表查询的时候常常需要用到where中的等于号来进新筛选,但是某些条件下不等于也是我们的业务要求之一
针对单个数据数据的筛选

SELECT * from ta
WHERE id !=2

sqlserver中的不等于用<>来表示

但是对于多个条件!=明显无法奏效,如筛选出多张表id的差集,这个时候需要用到not in

SELECT ta.id from ta
WHERE ta.id not in  (SELECT tb.id from tb)
and ta.id not in  (SELECT tc.id from tc)
and ta.id not in  (SELECT td.id from td)

查询出ta与tb、tc、td的差集

  • 作者:菜鸡rick
  • 原文链接:https://blog.csdn.net/whwwycl/article/details/118439220
    更新时间:2022-10-12 13:39:21