Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Problem with joining two select query statements. Expand / Collapse
Author
Message
Posted Friday, April 26, 2013 12:00 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 23, 2013 3:02 AM
Points: 25, Visits: 72
Hi All,

I Have Two Select Query Statement Result sets I want to combine those two sets.

The Below One Is my first query resultant set,

ID NAME HOURS
1 AAA 0
2 BBB 10
3 CCC 0
4 DDD 0

The Below One Is my Second query resultant set,

ID NAME HOURS
1 AAA 20
2 BBB 0
3 CCC 0
4 DDD 0

After Joining two results i.e., My First Query & Second Query i want to get like below one,

ID NAME HOURS
1 AAA 20
2 BBB 10
3 CCC 0
4 DDD 0

But i am not getting the result.

After Joining two results i am getting the final one like below but it was wrong

ID NAME HOURS
1 AAA 0
1 AAA 20
2 BBB 0
2 BBB 10
3 CCC 0
4 DDD 0

For the Joining two select queries am using Below Query

Select TT.ID,TT.NAME,ROUND((CAST((Sum(TJA.MINS)) as FLOAT)/60),0) AS HOURS
From MYTABLE1 as TT INNER JOIN MYTABLE2 as TB
On TT.ID=TB.ID INNER JOIN MYTABLE3 as TH
On TB.BID=TH.BID INNER JOIN MYTABLE4 as TJA
On TJA.HID=TH.HID
Where TJA.JID=41
group by TT.ID,TT.NAME
UNION
Select TJA.ID,TT.NAME,ROUND((CAST((Sum(TJA.MINS)) as FLOAT)/60),0) AS HOURS
From MYTABLE1 as TT INNER JOIN MYTABLE2 as TJA
On TT.ID=TJA.ID
wHERE TJA.JID=41
group by TJA.ID,TT.NAME


Please give the solution for me.

Thanks In Advance,
Venki Desai.
Post #1446805
Posted Friday, April 26, 2013 3:02 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 12:13 AM
Points: 2,631, Visits: 4,723
Duplicate post. Please post your replies here.
http://www.sqlservercentral.com/Forums/Topic1446842-1292-1.aspx



Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1446858
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse