0

我有两张桌子

表格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

我试图写这样的查询:

select t1.column
from table 1 t1
where not exists ( select 1 from table2 t2 where t1.column = t2.column)

但它给了我空的结果,任何人都可以修复查询吗?

4

2 回答 2

1

尝试这个:

Select name,column from table1
minus
select name,column from table2
于 2013-10-25T12:43:26.707 回答
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

于 2013-10-25T12:44:24.080 回答