Database Reference
In-Depth Information
7
Joining Tables
Information in Multiple Tables
We spent a lot of time while we were designing our tables removing redundant or duplicate
data from our database. Instead of inserting multiple instances of text into a table, we put
the text once into another table, and then inserted the primary key pointing to that data
into the table that would have contained the duplicates. This leads to very efficiently stored
data, but means that we have to join the tables to get the data back from them in a readable
form.
For instance, Figure 7.1 shows all the data that is stored in our log table. Notice that the
second and third columns contain foreign keys from the cookie and webpage tables. It may
be easy to remember that webpageID one is the Home page but what about the other IDs?
Also what is so special about cookieID two? It seems that they are the only person that has
looked at the website, so did they enter their name in the visitor book as well? We can
answer these sort of questions by joining tables together.
There are two basic types of joins in SQL:
the inner join, and
the outer join.
Figure 7.1
The Log table contents.
73
Search WWH ::




Custom Search