mysql SELECT NOT IN () — disjoint set?

后端 未结 6 1553
我寻月下人不归
我寻月下人不归 2021-02-20 11:22

I\'m having a problem getting a query to work, which I think should work. It\'s in the form

SELECT DISTINCT a, b, c FROM t1 WHERE NOT IN ( SELECT DISTINCT a,b,c          


        
6条回答
  •  我在风中等你
    2021-02-20 11:41

    As far as I know, NOT IN can only be used for 1 field at a time. And the field has to be specified in between "WHERE" and "NOT IN".

    (Edit:) Try using a NOT EXISTS:

    SELECT a, b, c 
    FROM t1 
    WHERE NOT EXISTS 
       (SELECT * 
       FROM t2 
       WHERE t1.a = t2.a AND t1.b = t2.b AND t1.c = t2.c)
    

    In addition, an inner join on a, b, and c being equal should give you all non-DISTINCT tuples, while a LEFT JOIN with a WHERE IS NULL clause should give you the DISTINCT ones, as Charles mentioned below.

提交回复
热议问题