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!

Union query loses duplicate record 1

Status
Not open for further replies.

shaunacol

Programmer
Joined
Jan 29, 2001
Messages
226
Location
GB
I have a union query which lists salesperson, GP and date of sale. There are 2 salespeolpe fields so this query unions salesperson1, GP and date of sale with salesperson2, GP and date of sale. The problem I have that there is occasionally duplicate information (for example a salesperson would have the exact GP and exact date listed twice (just because he happened to have the same GP for 2 particular sales on the same date)). My union query does not recognise this and one of the record just dissapears. Is there any way I can prevent this? I thought that perhaps if I sum the GP field then it will be added together instead of unioned but I don't think this is possible in a union query?
 
It doesnt work for me but maybe I am doing it wriong? My query is below - I added the ALL in as below:


SELECT ALL [CustomerID] AS [Customer], [DateOfSale], [TUrnover], [GP], [SalesOrderNo], [InvoiceNumber], [DateInvoicePaid], [SalesPerson1], [Sales1GP]
FROM [CommQry1]

UNION SELECT ALL [CustomerID] AS [Customer], [DateOfSale], [TUrnover], [GP], [SalesOrderNo], [InvoiceNumber], [DateInvoicePaid], [SalesPerson1], [Sales1GP]
FROM [CommQry2];

UNION SELECT ALL [CustomerID] AS [Customer], [DateOfSale], [TUrnover], [GP], [SalesOrderNo], [InvoiceNumber], [DateInvoicePaid], [SalesPerson1], [Sales1GP]
FROM [CommQry3];
 
How about:

Code:
SELECT [CustomerID] AS [Customer], [DateOfSale], [TUrnover], [GP], [SalesOrderNo], [InvoiceNumber], [DateInvoicePaid], [SalesPerson1],  [Sales1GP]
FROM [CommQry1]

UNION ALL  
SELECT [CustomerID] AS [Customer], [DateOfSale], [TUrnover], [GP], [SalesOrderNo], [InvoiceNumber], [DateInvoicePaid], [SalesPerson1], [Sales1GP]
FROM [CommQry2];

UNION ALL 
SELECT [CustomerID] AS [Customer], [DateOfSale], [TUrnover], [GP], [SalesOrderNo], [InvoiceNumber], [DateInvoicePaid], [SalesPerson1], [Sales1GP]
FROM [CommQry3];

 
THAT WORKS GREAT - THANK YOU!!!!
 
shaunacol,
If remou's answer is worth shouting about, how about clicking the link "Thank Remou vor this valuable post!" to recognize a helpful post.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top