Database Reference
In-Depth Information
it only uses if in this format. This may result in your join queries running faster. If nothing
else, it save a lot of confusing WHERE clauses!
Outer Joins
The inner join allows you to join two tables which have matching data in certain rows. In an
outer join, the whole of one table is returned, along with the matching rows in another
table. The first table is returned regardless of whether anything matches with it in the sec-
ond table. If that sounds confusing to you then don't worry too much. As usual a few exam-
ples will make it clearer.
LEFT JOIN
The LEFT JOIN is an outer join that uses the format that we just introduced in the section
on INNER JOIN as follows:
SELECT columns
FROM
firsttable
LEFT JOIN secondtable ON
firsttable.column = secondtable.column
To demonstrate the left join, we have to examine the results from the following query:
SELECT
webpage.title, log.datecreated
FROM
log, webpage
WHERE
webpage.id = log.webpageid
You should now recognize the above as an equi-join. Figure 7.9 shows the results.
What we are trying to display is a list of all of the webpages that we have on our site and
a relevant log entry for each page. However, if we look at Figure 7.9 we can see that we have
Figure 7.9
An equi-join fails to show all web pages.
Search WWH ::




Custom Search