我一直在使用有關子查詢的早期問題給出的建議。在這裏看到:sql - 與相關子查詢混淆
sql - multiple layers of correlated subqueries
SQL Server : left join results in fewer rows than in left table
我使用的MS SQL Server(我相信這是2005)。
什麼我想現在要做的是以下幾點:
select * from TableA as a
join (select * from TableB where RealDate = '4/20/2013 12:00:00 AM') as b
on a.id = b.id
這個結果:
我行的結果(稱它爲導致A),是從做以下獲得我想找到未在該查詢返回的行的結果,所有行:
select * from TableA as a
join TableC as c
on c.id = a.id
基本上我有一個情況第一次查詢結果246點的記錄,而第二曲結果在247條記錄中。我期待第一個結果返回247條記錄(所有這些記錄都應該在第二條記錄返回的記錄列表中)。所以現在我需要調查哪些記錄丟失,以便我可以採取適當的行動。
我試圖做類似以下,但收到的各種錯誤:
select * from (select * from TableA as a
join (select * from TableB where RealDate = '4/20/2013 12:00:00 AM') as b
on a.ul_id = b.id))
as result_A
where not exists (select 1 from (select * from TableA as a
join TableC as c
on c.id = a.ul_id) as result_B
where result_A.ul_id = result_B.id);