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

SQL join fucntion (3 table)

Status
Not open for further replies.

delphinewbie

Programmer
Dec 10, 2003
14
0
0
MY
The following is the corresponded table :

Customer
----------------
CustomerID
CustName
ProductID
SupplierID


Product
----------------
ProductID
ProductName
ProductDesc


Supplier
----------------
SupplierID
SupplierName
SupplierTelNo


I'm try to join all the 3 tables(Join Customer table with Product Table, and Customer Tabel with Supplier Table)
So what SQL statement should i used ?

I guess it should b something like this:

(Let's assume Customer Table is A, Product Table is B, and Supplier Table is C:)
So A.ProductID=B.ProductID, and A.SupplierID=C.SupplierID ....

I know how to join the table when it's with 2 tables. But how to join all 3 of the table??
Thx in advance for ur help..
 
You don't try to join all 3 tables together (ie s A=B, A=C, B=C).

You need to determine which table is the detail table, and then join the other master tables on to it. From here, it sort of looks as if your customer table is the detail table for some reason. Not quite sure what ProductID is doing in there though.

So your example join is correct. JOIN syntax differs depending on your brand of SQL. You would want to use inner joins, which are accomplished by something like this:

SELECT * FROM Customer, Product, Supplier
WHERE Customer.ProductID = Product.ProductID AND Customer.SupplierID = Supplier.SupplierID

That will give you all fields and a single record where the appropriate joins can be made.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top