SQL语句:三个同字段的表中,查找字段的重复值

如下,有三个表(Table1,Table2,Table3),字段相同。
目的:把Table3数据分类查询出来:三个表中同时出现过的;Table3和Table2中出现过的;Table1和Table3中出现过的;只在Table3中出现过的。

求SQL语句。

Table 1 Table 2 Table 3
学号 姓名 学号 姓名 学号 姓名
2568 小米 2685 陈晨 0168 阿真
3587 小明 0299 小聂 0987 阿强
0168 阿真 3587 小明 0002 阿杜
0987 阿强 0168 阿真 0007 狗蛋
0002 阿杜 0987 阿强 0782 猫剩
0007 狗蛋 0002 阿杜 2685 陈晨
0782 猫剩 0119 雪雪 0299 小聂
0135 小丽 0037 黑子
0986 阿易
0258 笑笑
0955 石头
最新回答
峋姗簌下落

2024-05-06 08:01:15

  1. select 学号 from table1 where 学号  in ( select 学号 from table2) and 学号 in (select 学号 from table3)

  2. select 学号 from table2 where 学号  in ( select 学号 from table3) 

  3. select 学号 from table1 where 学号  in ( select 学号 from table3) 

  4. select 学号 from table3 where 学号 not in ( select 学号 from table1) and 学号 not in  ( select 学号 from table2)