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

QUICK JOINS question

Status
Not open for further replies.

alphacooler

Programmer
Aug 29, 2005
73
US
I am unsure as to the proper order in which to do joins. When doing INNER JOINS (when many tables are involved), can I only join two tables that are placed back to back in order, or can I inner join table 1 with table 6 (1 and 6 being their order listed). Also does the same apply for LEFT JOINS, or can I join any two tables no matter where they come in order?

Thanks.
 
my experience is that you should start with the table that has the most specificity, i.e. the table for which you have a WHERE condition

for example, to find all articles in a particular category, you would have

FROM categories
INNER
JOIN articles
ON articles.category_id = categories.id
WHERE categories.owner = 937

from this point forward, you may add additional tables, provided that each one you add has a join condition that references a table already mentioned

put all your INNER JOINs first, then your LEFT OUTER JOINs

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top