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

首頁 > 數據庫 > MySQL > 正文

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

2020-01-18 23:20:20
字體:
來源:轉載
供稿:網友
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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 尼木县| 武胜县| 河东区| 屏边| 新乡县| 明溪县| 高要市| 北碚区| 玛沁县| 夏津县| 长海县| 江油市| 阿拉善右旗| 七台河市| 遂宁市| 绥中县| 张家口市| 广南县| 醴陵市| 湘潭县| 镇远县| 永平县| 嘉鱼县| 崇阳县| 保靖县| 灯塔市| 手游| 巴彦淖尔市| 华亭县| 德令哈市| 大兴区| 巩留县| 祁连县| 赤水市| 中江县| 四子王旗| 子洲县| 绥芬河市| 公安县| 盖州市| 南汇区|