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

QUERY FOR 4 TABLES 1

Status
Not open for further replies.

netrusher

Technical User
Feb 13, 2005
952
US
Hello again everyone:

I have a new problem! I have four dbf files imported as tables. Each table has the same fields. One of the Fields in the tables is Parts. What I want to find if possible is the following:

1. I want to see all unique parts in these tables. If table 1, 2, 3, & 4 all have part 1 I only want to see it one time. I guess what I am saying is I really only want to see each part one time even if it is in all 4 tables, 3 tables, 2 tables or 1 table. Can this be done? I hope you can understand this request and thanks for the help!
 
Have a look at UNION query, by default it retrieves only distinct values.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
a simple union query should do the trick:

SELECT * FROM TABLE1
UNION
SELECT * FROM TABLE2
UNION
SELECT * FROM TABLE3
UNION
SELECT * FROM TABLE4

You may need to add DISTINCT to each clause if there are duplicates within a table, but the UNION will only show one record even if it's in all 4 tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top