日期:2014-05-17  浏览次数:20492 次

怎么搜索两个表之间的不同单号
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
)