Database Reference
In-Depth Information
Figure 7.11
A left join.
This time this query is saying: “Show me every title in the webpage table that matches a
row in the log table, and all of the rest of the datecreated entries in the log table”. Figure 7.12
shows this query running. It actually gives the same result set as the equi-join that we ran
at the start of this chapter, but it has been executed as a left join. As every row in the log
table must match a row in the webpage table, to maintain referential integrity, no NULLs
will appear.
RIGHT JOIN
As we have a left join, it follows that we will also have a right join. The format of a right join
is similar to that of a left join, as below:
SELECT columns
FROM
firsttable
RIGHT JOIN secondtable ON
firsttable.column = secondtable.column
This query is saying: “Show me every column in the first table that matches a column in
the second table, and all of the rest of the second table entries”. We'll run this with our pre-
vious example again:
SELECT webpage.title, log.datecreated
FROM
log
RIGHT JOIN webpage ON
webpage.id = log.webpageid
If you have still got the script on the screen, just change the LEFT keyword to RIGHT and
run it again.
Search WWH ::




Custom Search