Need SQL help with combining data from multiple tables

rockman

Senior Member
Local time
Today, 03:19
Joined
May 29, 2002
Messages
190
I have a database with a table of employees, a table of contacts, and a table of suppliers. I wish to create an "Address Book" form that will generate a combined, sorted list of the Name and PhoneNumber fields from all three tables. I need some slick SQL to combine the data into a new recordset. Example:

Code:
tblEmployees:
[U]Name        PhoneNumber[/U]
Smith         555-2342
Jones         555-9634

tblContacts:
[U]Name        PhoneNumber[/U]
Williams      555-1287
Tuckman       555-3970

tblSuppliers:
[U]Name        PhoneNumber[/U]
Boone         555-4478
Drake         555-1925
I would like my recordset to contain:

Code:
rsAddressBook:
[U]Name        PhoneNumber[/U]
Boone         555-4478
Drake         555-1925
Jones         555-9634
Smith         555-2342
Tuckman       555-3970
Williams      555-1287
THANKS FOR ANY HELP!
Jeff
 
You don't need no recordset.
Create an UNION query and base your form on this query:

SELECT Name, PhoneNumber
FROM tblContacts
UNION
SELECT Name, PhoneNumber
FROM tblEmployees
UNION
SELECT Name, PhoneNumber
FROM tblSuppliers
ORDER BY 1;

RV
 
Thanks RV

The UNION command is exactly what I needed.

Jeff
 

Users who are viewing this thread

Back
Top Bottom