欢迎光临 - 我的站长站,本站所有资源仅供学习与参考,禁止用于商业用途或从事违法行为!

数据库教程

sql两个求表的差语法

数据库教程 我的站长站 2020-09-16 共231人阅读

sql求两个表t1和t2,表中只有一个字段c1。

求两个表的差。即存在于t1,但不存在于t2中的记录。

方法1.

select c1 from t1 where c1 not in (select c1 from t2)

方法2.

select c1 from t1 where not exists(select * from t2 where t1.c1=t2.c1)

方法3.

select t1.c1 from t1 left join t2 on t1.c1=t2.c1 where t2.c1 is null