Solved

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

Posted on 2011-09-18
6
204 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now