相交,減號關鍵字在MySql中不存在,變通辦法是
- 內部聯接,並
- 子查詢或
- 左聯接分別。
請看這裏
Doing INTERSECT and MINUS in MySQL
我給一個鏡頭(雖然我是一個SQL Server的傢伙)
輸入:
id_user id_movie
101 1
102 2
102 3
104 4
102 5
107 6
102 2
103 3
109 9
110 2
110 3
輸出通過使用相交(如果在SQL Server中運行)將是
id_user
102
110
MySQL的兼容的查詢使用
查詢1Inner join
select distinct a.id_user
from Rating a
join Rating b on a.id_user = b.id_user
where a.id_movie = 2 and b.id_movie = 3
使用查詢2Cross join
select distinct a.id_user
from Rating a, Rating b
where a.id_user = b.id_user
and a.id_movie = 2
and b.id_movie = 3
查詢3使用子查詢
上面已經回答。
錯誤是因爲MySQL不支持'INTERSECT'關鍵字。 – 2009-12-10 02:37:02