similar functionality to SQL Server's EXCEPT operand in MySQL?

时间秒杀一切 提交于 2019-12-21 05:22:12

问题


Is there an operand/function/command in MySQL similar to the EXCEPT operand in SQL Server?

EXCEPT returns any distinct values from the left query that are not also found on the right query.

This statement should give me the distinct values.

SELECT * FROM table1
EXCEPT
SELECT * FROM table2;

How can this be achieved in MySQL?


回答1:


The best you could do is use a NOT EXISTS. Something like:

SELECT DISTINCT *
    FROM table1
    WHERE NOT EXISTS(SELECT NULL 
                         FROM table2
                         WHERE table1.x = table2.x)


来源:https://stackoverflow.com/questions/6682084/similar-functionality-to-sql-servers-except-operand-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!