Understanding SQL Joins - ...Two Steps Right
(Page 7 of 10 )
Just as there's a left join, there's also a "right join", which does exactly what a left join does, but in reverse. Consider the following query,
SELECT * FROM a RIGHT JOIN c ON a1=c1;
which translates to "select all the rows from the right side of the join (table c) and, for each row selected, either display the matching value from the left side (table a) or display an empty row" and displays
+------+------+-----+------+
| a1 | a2 | c1 | c2 |
+------+------+-----+------+
| NULL | NULL | 90 | m |
| NULL | NULL | 100 | n |
| NULL | NULL | 110 | o |
+------+------+-----+------+
3 rows in set (0.06 sec)
All the rows from the right side of the join - table "c" - appear in the final resultset. Those which have a corresponding value on the left side - table "a" - as per the match criteria a1 = c1 have that value displayed; the rest have a null row displayed.
Next: The Bookworm Turns >>
More MySQL Articles
More By The Disenchanted Developer, (c) Melonfire