Putting it back together Inner Joins Putting it back together
Overview Normalization is the process of splitting information into separate tables, but often we want to see and use the information together Joins bring the information from separate tables back together for queries
Types of Joins There are several types of joins Inner Joins Outer Joins Cross Joins Full Joins We are only going to worry about inner joins for now
Keywords Inner joins introduce three new keywords INNER JOIN ON
A Simple Inner join SELECT ArtistName, Track_Title FROM Artist a INNER JOIN Tracks t ON a.ArtistID=t.ArtistID In the SELECT clause list all the fields you wish to see from all the tables. Put one of the tables in the FROM Clause Place the other table after the INNER JOIN Clause In the ON clause you tell which field relates the tables (key and Foreign Key, though the order doesn’t matter) Note the aliasing of the tables
Joining More than 2 Tables SELECT ArtistName, Track_Title, Cd_Title FROM Artists a INNER JOIN Tracks t ON a.ArtisitID=t.ArtistID INNER JOIN Cds c ON c.CD_ID = t.CD_ID WHERE ArtistName=‘U2’
In Access To do the previous join in Access you would need to nest the join statements. The next slide shows how Access handles the inner join It is often easier to use the alternative syntax (Last slide)
Access Inner Join SELECT ArtistName, CD_Title, Track_Title FROM CDs INNER JOIN (Artists INNER JOIN Tracks ON Artists.ArtistID = Tracks.ArtistID) ON CDs.CD_ID = Tracks.CD_ID WHERE (((ArtistName)="U2"));
An Alternate Way SELECT ArtistName, Track_Title, Cd_Title FROM Artists a, Tracks t, Cds c WHERE a.ArtistID=t.ArtistID AND c.CD_ID=t.CD_ID AND ArtistName=‘U2’ This is an older way. It was the only way Oracle supported before 9i