博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 代替intersect_MySQL不支持INTERSECT跟MINUS,及其替代方法
阅读量:5149 次
发布时间:2019-06-13

本文共 964 字,大约阅读时间需要 3 分钟。

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

转载地址:http://wodnv.baihongyu.com/

你可能感兴趣的文章
list control控件的一些操作
查看>>
一月流水账
查看>>
判断字符串在字符串中
查看>>
HashPump用法
查看>>
cuda基础
查看>>
Vue安装准备工作
查看>>
oracle 创建暂时表
查看>>
201421410014蒋佳奇
查看>>
Xcode5和ObjC新特性
查看>>
LibSVM for Python 使用
查看>>
Centos 7.0 安装Mono 3.4 和 Jexus 5.6
查看>>
CSS属性值currentColor
查看>>
java可重入锁reentrantlock
查看>>
浅谈卷积神经网络及matlab实现
查看>>
解决ajax请求cors跨域问题
查看>>
《收获,不止Oracle》pdf
查看>>
Real-Time Rendering 笔记
查看>>
如何理解HTML结构的语义化
查看>>
Activity之间的跳转:
查看>>
实验四2
查看>>