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

3 table join

Status
Not open for further replies.

croakyfrog

Technical User
Dec 4, 2001
51
GB
hi

i have 3 tables

table1 with field1, field2, field3

table2 with field1, field4

table3 with field2, field5

i want the query to produce all of the above fields but i cant seem to get the query quite right

can anyone help?

:)
 
Isounds like you want to join the columns together. Something like:

[tt]
Select t1.Field1, t1.Field2, t1.Field3,
t2.Field1, t2.Field4,
t3.Field2, t3.Field5
From Table1 t1
INNER JOIN Table2 t2
ON t1.Field1 = t2.Field1
INNER JOIN Table3 t3
ON t1.Field2 = t3.Field2

This will select all the records that have a match in all three tables.

If you wanted to make sure you selected all Table1 records even if there was no match in the other 2 tables, then you would change the INNER JOINs to LEFT JOINs.
 
totally brilliant! ps i i tried to give you a star but there was an error.

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top