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

Joining multiple Tables

Status
Not open for further replies.

CLIRAM

Programmer
Joined
Dec 14, 2004
Messages
2
Location
US
Given 3 tables A, B, and C containing the following contents

A.CID
A.PID
A.Data

B.CID
B.Name

C.CID
C.PID
C.Name

What SQL statement would give a result set containing all data in Table A and the associated Name fields from Tables B and C. PID in Table A may be blank. PID in Table C is never blank.

If this information is not clear enough let me know and I will try to expand on it.

Any help would be appreciated.
 
What are the relationships ?
The A.CID refers to B or to C (in conjunction with PID) ?
A starting point:
SELECT A.CID,A.PID,A.Data,B.CID,B.Name,C.CID,C.PID,C.Name
FROM (A LEFT JOIN B ON A.CID=B.CID)
LEFT JOIN C ON A.CID=C.CID AND A.PID=C.PID

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks,

This appears to do what we need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top