我正在编写一个简单的选择语句来比较两个不同的表。
table 1 table 2
a a
b b
c c
H d
e
f
我需要选择表 1 中表 2 中不存在的任何项目。
你有几个选择,其中之一是
select table1.col from table1 where
not exists (select col from table2 where table2.col = table1.col)
子查询应该这样做:
Select * from table1
where Id not in
(select distinct col from table2)
SELECT table_1.name
FROM table_1
LEFT JOIN table_2 ON table_1.name = table_2.name
WHERE table_2.name IS NULL
因为看起来只有一列。尝试这个。
select * from table a -- select all of the things in a
minus
select * from table b -- remove from it the things in b