Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
I've executed two select statements 

output of 1 is 

Name    Qty     Avg
AAAA     12      10.2
bbbb     10      10.5


output of 2 is 

Name    Qty2    Avg2
CCCC     10      10.5
AAAA     12      12.5



What i Actually want is 

Name   Qty    Avg   Qty2   Avg2
AAAA   12     10.2   12     12.5
bbbb   10     10.5   null   null
CCCC   null   null   10     10.5



Can Someone plz solve this Query??
Posted

Below Query will provide ur solution..


SQL
 SELECT  A.[Name]
    ,B.[Qty]
    ,B.[Avg]
    ,C.Qty2
    ,C.Avg2
      FROM (select name from [dbo].[1] union select name from [dbo].[2])as A
left join
[dbo].[1] AS B on A.Name =B.Name  left join [dbo].[2] AS C
ON A.Name =C .Name
 
Share this answer
 
v3
 
Share this answer
 
Use CTE (Common table Expression) for this:-

With T1
as
( // first select query ),
T2
as
( // second select query )
select T1.Name,T1.Qty,T1.Avg,T2.Qty2,T2.Avg2 from T1


Hope this will help you......
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900