-
兩個要求交集的表(列)的結構要一致,對應的欄位數,欄位型別都應該相同;將兩個資料的資料列用 UNION ALL 關鍵字合併;將上面的所有需要比較的列 GROUP BY ;最後 HAVING COUNT(任意一列,不能多列)>1,那麼就是交集。
SELECT a.* FROM( SELECT * from teacher UNION ALL SELECT * from student)a GROUP BY a.id,a.name,a.sex HAVING COUNT(a.sex)>1
-
SELECT * FROM student AS a JOIN teacher AS b ON a.name =b.name AND a.ID=b.ID或者SELECT * FROM student AS a inner JOIN teacher AS b ON a.name =b.name AND a.ID=b.ID
-
SELECT * FROM student AS a where a.name in (select name from teacher )AND a.ID in (select ID from teacher);
-