How do you construct a INNER JOIN statement from three tables?


I am experimenting with this and trying to learn...  

How do you contruct a INNER JOIN statement from three tables?  Please explain in simple terms.

Table1.subcatname  =  Table2.subcategory

Table1.sku = Table3.productid

Thanks for your help!!

Who is Participating?
Also, if your Subcatname is a string, consider changing that to a primary key ID column (integer)... that way you can change the name of the subcategory, and the original table is unharmed.

SELECT Products.ProductName, SubCategory.Name
FROM Products
INNER JOIN SubCategory ON Products.SubCategoryId = SubCategory.Id

Where your subcategory table is named SubCategory

Or you could take it a step farther and make products fall into multiple categories with a link table.
Scott MadeiraCommented:
something like this....

select * 


Table1 T1
left join Table2 on (T1.subcatname = T2.subcategory)
left join Table3 (T1.sku = T3.productid)

Open in new window

You have two separate join statements where you put the table you are joining to and then after the ON keyword you show the "link" or relationship between the two tables.  you don't need to use the table aliases but it does make for less typing.
exactly like this...

SELECT * FROM table1
INNER JOIN table2 ON table1.subcatname = table2.subcategory
INNER JOIN table3 ON table1.sku = table3.productid

The left join will give you (potentially) empty subcategories and products. Inner Join forces the relationship to be there.

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

rlb1Author Commented:
I really appreciate your help... I am finishing another project.  Will be back shortly.
Rock on... I don't know how I ended up on this to begin with, but my syntax is for MS SQL server specifically, I'm not sure what your db is... but the principles are the same, your syntax may be slightly different.

Please come back and let us know how it went!
rlb1Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.