Sql Select语句选择表1中表2中不存在的项
我正在编写一个简单的select语句来比较两个不同的表Sql Select语句选择表1中表2中不存在的项,sql,Sql,我正在编写一个简单的select语句来比较两个不同的表 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
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 * from table a -- select all of the things in a
minus
select * from table b -- remove from it the things in b
显示完整的表1、表2数据我不想看到所有的数据,但我希望看到您所称的列以及表之间的关系。这是“规范”的正确答案,但我会从最外层的查询中选择*(检索行的所有详细信息),并使用主键列(我希望调用
ID
)作为子查询的选择。
select * from table a -- select all of the things in a
minus
select * from table b -- remove from it the things in b