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!

Query help - need to return columns even without matches

Status
Not open for further replies.

GATVA

Programmer
Joined
Jan 16, 2009
Messages
1
Location
US
I need help with a query in Access where I am trying to return all records in one table whether or not there is a match to all of the tables that I am selecting from. I'll do my best to explain this.

For example, I have table A, B, C, D.

I need to return a row for every record in A. I want to return data from B if there is a match, otherwise null. I want to return data from C if there is a match, otherwise null. I want to return data from D if there is a match, otherwise null.

So if A is related to B,C,D by zip code, I want to return the data in B,C, or D if there is a matching zip code in the table. If not I want the cloumn to return a null value. So If I only find a match in C, it would be like this:

Zip B value C value D value
24502 24502

I hope this makes sense. Thanks in advance.
 
what you need is an outer join (check out Understanding SQL Joins)
Code:
SELECT * FROM TableA a
LEFT OUTER JOIN TableB b on a.Zipcode = b.zipcode
LEFT OUTER JOIN TableC c on a.Zipcode = c.zipcode
LEFT OUTER JOIN TableD d on a.Zipcode = d.zipcode

Leslie

Have you met Hardy Heron?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top