?
Solved

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

Posted on 2011-09-18
6
Medium Priority
?
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Assisted Solution

by:Scott Madeira
Scott Madeira earned 800 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 1200 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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

771 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