question

Scott Adderson avatar image
Scott Adderson asked

Concatenating queries

I need to join two queries together but they don't have exactly the same structure..

the structure of query one is :

name department totalsalesafrica

the sturcture of query two is :

name department totalsaleseurope

Data query one..

fred dvd's 250

dave records 300

don sheetmusic 150

Data query two

fred dvd's 100

dave records 350

denise dvd's 200

Resultant query

fred dvd's 250 100

dave records 300 350

don sheetmusic 150 0

denise dvd's 0 200

Thanks

Scott

sql-server-2008query
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

RickD avatar image RickD commented ·
and what is your issue? Do you have the two queries as it is easier to explain with your own queries than making them up from scratch? Also, please use the code tags.
0 Likes 0 ·

1 Answer

·
Jay D avatar image
Jay D answered

I don't see the difference in your structure, assuming that SalesEurope and SalesAfrica are both of the same data type.

SELECT myCategory, myLocation, SUM(myAmount) AS [TotalSales]            
FROM myTable            
GROUP BY myCategory, myLocation            

You don't really need two separate queries assuming the data is coming from the same table. Please post your queries and data structure as it's easier to figure out what your asking. Otherwise, it's a shot in the dark.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.