MySQL不支持INTERSECT和MINUS及其替代方法

如果有天我们湮没在人潮之中,庸碌一生,那是因为我们没有努力要活得丰盛。善于与人沟通,适度采纳别人意见。
Doing INTERSECT and MINUS in MySQL Doing an INTERSECT An INTERSECT is simply an inner join where we compare the tuples of one table with those of the other, and select those that appear in both while weeding out duplicates. So
 
SELECT member_id, name FROM a
INTERSECT
SELECT member_id, name FROM b
can simply be rewritten to
 
SELECT a.member_id, a.name
FROM a INNER JOIN b
USING (member_id, name)
Performing a MINUS
To transform the statement
 
SELECT member_id, name FROM a
MINUS
SELECT member_id, name FROM b
into something that MySQL can process, we can utilize subqueries (available from MySQL 4.1 onward). The easy-to-understand transformation is:
 
SELECT DISTINCT member_id, name
FROM a
WHERE (member_id, name) NOT IN
(SELECT member_id, name FROM table2);
Of course, to any long-time MySQL user, this is immediately obvious as the classical use-left-join-to-find-what-isn't-in-the-other-table:
 
SELECT DISTINCT a.member_id, a.name
FROM a LEFT JOIN b USING (member_id, name)
WHERE b.member_id IS NULL

以上就是MySQL不支持INTERSECT和MINUS及其替代方法。除了少许的天份之外,大多是靠努力得来的“三分天才,七分努力。”是成功不变的法则,一个不愿或不肯努力的人,比起原地踏步,还要糟糕,所以要好好把握一分一秒的时刻,作为迈向下一步的准备,如此才能扎实稳固。更多关于MySQL不支持INTERSECT和MINUS及其替代方法请关注haodaima.com其它相关文章!

您可能有感兴趣的文章
MySQL版本低了不支持两个时间戳类型的值如何解决方法

如何解决Node.javascriptmysql客户端不支持认证协议引发的问题

MySQL中Union子句不支持orderby的如何解决方法

Ubuntu15下mysql5.6.25不支持中文的如何解决办法

MySQL8.0.18HashJoin不支持left/rightjoin左右连接问题