我有两个mysql表
表A
colA1 colA2
1 whatever
2 whatever
3 whatever
4 whatever
5 whatever
6 whatever
第二个表基本上是从tableA派生的,但是删除了一些行
tableB的
colB1 colB2
1 whatever
2 whatever
4 whatever
6 whatever
如何编写查询以从上面两个表中获取缺失行的表
即
colC1 colC2
3 whatever
5 whatever
答案 0 :(得分:10)
SELECT t1.*
FROM TableA t1 LEFT JOIN
TableB t2 ON t1.ID = t2.ID
WHERE t2.ID IS NULL
答案 1 :(得分:0)
这样的事情:
select *
from tableA
where not exists (
select 1
from tableB
where tableB.colB1 = tableA.coldA1
)
即,您从tableA
中选择了tableB
中没有等效数据的数据。
答案 2 :(得分:0)
select * from tableA where colA1 not in ( select colA1 from tableB ) ;