View Single Post
12-15-2007, 06:38 PM
Join Date: Nov 2007
Although I agree with
(especially about creating an INDEX on most (if not all) columns you regularly perform joins on), I've always found the easiest way to look at the difference between a RIGHT and LEFT JOIN is by realizing that the LEFT join pulls data from the table referenced on the
side of the SQL statement, e.g.
SELECT t1.c1, t1.c2, t2.c1 FROM table1 AS t1 LEFT OUTER JOIN table2 AS t2 USING (c3)
Obviously table1 is on the
so all results will be pulled from table1 whereas NULL will represent columns in missing records from table2 (on the right). The RIGHT OUTER JOIN (not used as often, in my experience) would represent all records from table2 (the right hand table) with NULL representing missing values from table1.
Note that both LEFT and RIGHT join statements are implied OUTER joins, but you can specifically use the OUTER keyword to avoid confusion.
Additionally, you can think of the difference between the INNER and OUTER joins as being the result of the join itself; the INNER join returns values only from
the set of matched records. In other words, only records will be returned where there is a match on the conditions. The OUTER join also returns records 'outside' the parameters of the match, based on the table on the left or the right. Get it?
View Public Profile
Send a private message to SOCK
Find More Posts by SOCK