求一查询语句!急~~~~~~
表a (订单)
id(自增长字段) order_id(订单号) handin_time(交货日期) num(订单数量)
1 20070306001 20070318 20
2 20070306002 20070318 30
3 20070306003 20070318 40
4 20070306004 20070316 32
表 b(回单)
id(自增长字段) order_id(订单号) handin_time(交货日期) h_num(回单数量)
1 20070306001 20070318 20
2 20070306002 20070318 30
3 20070306004 20070316 30
问题是如何得到那些不在表b(回单) 中的订单号 和 表a(订单) 跟 表b(回单) 中订单数量和回单数量不同的订单号
------解决方案--------------------select * from a where order_id no in (select order_id from b)
union all
select * from a , b where a.order_id = b.order_id and a.num <> b.h_num
------解决方案--------------------Select A.order_id From A Where order_id Not In (Select Distinct order_id From B )
Union
Select A.order_id From A Inner Join B On A.order_id = B.order_id And A.num != B.h_num