Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge with an UNION

Status
Not open for further replies.

SebFr

Programmer
Joined
May 28, 2006
Messages
12
Location
US
Hi,

I've two separated queries that both return two columns: the first one returns NAMES | #ORDERS, and the second one NAMES | #SALES

I would like to merge those two queries to one query with the columns like that: NAME | #ORDERS | #SALES.
I tried to add the missing column on each query with a value to 0 and then make an UNION between the two queries but I get 2 rows for each name: NAME | 0 | #SALES and NAME | #ORDERS | 0. I want to merge that to get only one row per name.

Can anyone tell me how to do that please? Hope I was clear enough...

Thanks
 
Code:
SELECT A.Names, A.#Orders, B.#Sales
FROM FirstQuery A
INNER JOIN SecondQuery B ON A.Names = B.Names

replace FirstQuery and SecondQuery with the correct query names (First Query is the orders)

You may find Understanding SQL Joins helpful.

HTH

Leslie

Have you met Hardy Heron?
 
Thanks Leslie.
Exactly what I wanted.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top