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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Union Qry - Need to use Distinct? 1

Status
Not open for further replies.

Zed5010

IS-IT--Management
Oct 9, 2005
42
CA
Need help: I have 2 tables : ORDERS & PURCHASES and need to calculate the difference between items purchased and ordered. Both tables contain fields (STYLE and COLOR). I need to extract records from the PURCHASES table that are not in the ORDERS table ie. combination of style and color not found in ORDERS. Certain style/color combinations were not ordered.


Orders QRY

Style Color Units
A Blue 1
A White 1
A Green 1
B White 1
B Red 1
C Blue 1

Purchases QRY

Style Color Units
A Black 4
B White 3
B Red 2
B Green 1
C Blue 9

Desired QRY
(All Orders incl. purchases of colors not in Orders)

Style Color Units
A Black 4
A Blue -1
A White -1
A Green -1
B White 2
B Red 1
B Green 1
C Blue 8


Thanks
 
SELECT P.*
FROM Orders O RIGHT JOIN Purchases P
ON O.Style = P.Style AND O.Color = P.Color
WHERE O.Style Is Null

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top