1

我正在编写一个简单的选择语句来比较两个不同的表。

table 1  table 2
a         a  
b         b
c         c
H         d
          e
          f

我需要选择表 1 中表 2 中不存在的任何项目。

4

4 回答 4

1

你有几个选择,其中之一是

select table1.col from table1 where 
not exists (select col from table2 where table2.col = table1.col)
于 2013-10-09T00:40:00.943 回答
1

子查询应该这样做:

Select * from table1 
where Id not in 
  (select distinct col from table2)
于 2013-10-09T00:40:26.940 回答
1
SELECT table_1.name
FROM table_1
    LEFT JOIN table_2 ON table_1.name = table_2.name
WHERE table_2.name IS NULL
于 2013-10-09T00:43:54.850 回答
0

因为看起来只有一列。尝试这个。

select * from table a -- select all of the things in a
minus
select * from table b -- remove from it the things in b
于 2013-10-09T00:55:20.813 回答