Solved

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

Posted on 2011-09-18
6
214 Views
Last Modified: 2012-06-22
Experts,

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!!





0
Comment
Question by:rlb1
  • 3
  • 2
6 Comments
 
LVL 14

Assisted Solution

by:Scott Madeira
Scott Madeira earned 200 total points
ID: 36557812
something like this....

 
select * 

from 

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.
0
 
LVL 7

Expert Comment

by:NauticalNonsense
ID: 36557817
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.

Cheers!
0
 
LVL 7

Accepted Solution

by:
NauticalNonsense earned 300 total points
ID: 36557829
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.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:rlb1
ID: 36587014
I really appreciate your help... I am finishing another project.  Will be back shortly.
0
 
LVL 7

Expert Comment

by:NauticalNonsense
ID: 36587301
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!
0
 

Author Closing Comment

by:rlb1
ID: 36817479
Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Selecting SUM data from mysql table with PHP 4 20
paypal ipn to mysql 3 39
Download tables into separate sheets 3 28
Loop through multiple arrays 13 29
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question