Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Problem with joining two select query statements.


Problem with joining two select query statements.

Author
Message
venkidesaik
venkidesaik
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 73
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.
Kingston Dhasian
Kingston Dhasian
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3005 Visits: 5016
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/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search