mysql SELECT NOT IN () — disjoint set?

后端 未结 6 1557
我寻月下人不归
我寻月下人不归 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:44

    I had trouble figuring out the right way to execute this query, even with the answers provided; then I found the MySQL documentation reference I needed:

    SELECT DISTINCT store_type
    FROM stores 
    WHERE NOT EXISTS (SELECT * FROM cities_stores WHERE cities_stores.store_type = stores.store_type);
    

    The trick I had to wrap my brain around was using the reference to the 'stores' table from the first query inside the subquery. Hope this helps (or helps others, since this is an old thread.)

    From http://dev.mysql.com/doc/refman/5.0/en/exists-and-not-exists-subqueries.html

提交回复
热议问题