Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to change the below sql script and use UNION

SELECT C.Customer_ID, C.Name, COUNT (I.Invoice_No) AS NumberOfInvoices, SUM (I.Total) AS SumOfTotal
FROM Customer C
LEFT JOIN Invoice I ON C.Customer_ID=I.Customer_ID
GROUP BY C.Customer_ID, C.Name

Thank you.

What I have tried:

I thought of creating a temp table
Posted
Updated 11-Oct-16 0:19am
Comments
Wendelius 10-Oct-16 3:48am    
Converting join directly to union yields to different results. What is it you're trying to achieve?

Thanks, this is what I did
SQL
SELECT C.Customer_ID, C.Name, Null,Null
FROM Customer C
UNION
SELECT I.Customer_ID, Null, COUNT (I.Invoice_No) AS NumberOfInvoices, SUM (I.Total) AS SumOfTotal
FROM Invoice I
GROUP BY I.Customer_ID, C.Name
 
Share this answer
 
Read: SQL UNION Operator[^]

Good tutorial site: SQL Tutorial[^]
 
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