Your query construct is not correct. I changed a bit.
I dont think there will be any difference. But, you can check against your actual data.
Create Table TableA(aid int, Col1 int)
Insert into TableA Select 1,1000
Insert into TableA Select 2,1000
Create Table TableB(bid int, aid int, colb char(1))
Insert into TableB Select 1,1,'r'
Insert into TableB Select 2,1,'e'
Insert into TableB Select 1,2,'r'
Insert into TableB Select 2,2,'e'
Insert into TableB Select 5,3,'r'
select a.aid,aa.ca,aa.cb
from TableA a
left join
(select a.aid, b.colb ca ,b1.colb cb
from TableA a
left join TableB b on a.aid=b.aid and b.colb='r'
left join TableB b1 on a.aid=b1.aid and b1.colb='e'
) aa on a.aid = aa.aid
where a.aid in (1,2)
select a.aid,aa.ca,aa.cb
from TableA a
left join
(select a.aid, b.colb ca ,b1.colb cb
from TableA a
left join TableB b on a.aid=b.aid and b.colb='r'
left join TableB b1 on a.aid=b1.aid and b1.colb='e'
Where a.aid in (1,2)
) aa on a.aid = aa.aid
where a.aid in (1,2)
Drop table TableA,TableB
No comments:
Post a Comment