国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 數(shù)據(jù)庫(kù) > MySQL > 正文

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

2024-07-24 13:05:38
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
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

復(fù)制代碼 代碼如下:


SELECT member_id, name FROM a
INTERSECT
SELECT member_id, name FROM b



can simply be rewritten to

復(fù)制代碼 代碼如下:


SELECT a.member_id, a.name
FROM a INNER JOIN b
USING (member_id, name)



Performing a MINUS
To transform the statement

復(fù)制代碼 代碼如下:


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:

復(fù)制代碼 代碼如下:


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:

復(fù)制代碼 代碼如下:


SELECT DISTINCT a.member_id, a.name
FROM a LEFT JOIN b USING (member_id, name)
WHERE b.member_id IS NULL

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 绥阳县| 新野县| 德保县| 广水市| 涿州市| 会宁县| 房产| 青州市| 永康市| 特克斯县| 延安市| 综艺| 延川县| 衡山县| 辰溪县| 平舆县| 固始县| 平潭县| 巨鹿县| 济阳县| 五台县| 阳新县| 五家渠市| 无棣县| 鄂温| 博爱县| 蒙阴县| 三穗县| 朝阳县| 雅江县| 明溪县| 偏关县| 牟定县| 安新县| 沙河市| 高平市| 内乡县| 华阴市| 普陀区| 济阳县| 乐亭县|