读书人

如何搜索两个表之间的不同单号

发布时间: 2013-03-10 09:38:39 作者: rapoo

怎么搜索两个表之间的不同单号
tsms_export,tsms_exportdetail这两个表,都有单号i_no这一列,但是有一些单号tsms_export里边查不到,tsms_exportdetail里边能查到,用什么能查出这些单号来呢?请教
[解决办法]

select i_no from tsms_exportdetail a where not exists(select 1 from tsms_export b where a.i_no=b.i_no)

[解决办法]
主单跟详单呗

select * from tsms_export a right join
(select distinct i_no from tsms_exportdetail) b on a.i_no=b.i_no
where a.i_no is null
[解决办法]
select * from tsms_exportdetail a
where not exists (
select 1 from tsms_export
where i_no = a.i_no
)

读书人网 >SQL Server

热点推荐