我有两个表格
表1
name | column
animals | fish
animals | cow
buildings| house
cars | BMW
cars | Ford
表2
name | column
|
animals | fish
|
buildings| house
cars | Ford
我试着写一个查询显示缺少的2列(宝马和牛)这样:
name | column
animals | Cow
Cars | BMW
我试着写这样的查询:
选择t1.column
从表1 t1中 哪里不存在(从table2 t2中选择1,其中t1.column = t2.column)
但它给我空的结果,任何人都可以修复查询吗?
答案 0 :(得分:1)
试试这个:
Select name,column from table1
minus
select name,column from table2
答案 1 :(得分:1)
SELECT * FROM table_1 t1 WHERE
NOT EXISTS (SELECT 1 FROM table_2 t2 WHERE t1.column = t2.column);
SQLFiddle: http://sqlfiddle.com/#!2/399b2d/7