Inner Join

I want to look at the top 10 laps led in a  race, by driver, since 2000.  I can run a simple query in one of my tables to display this info, but this table doesn’t include the track:

Table Name: Results
ss3

I have a second table called RaceID, which includes the name of the track.
ss4

Both tables have the same  primary key in the RaceID header, so we can use the Inner Join command to connect the track name into the results:

SELECT     TOP (10) dbo.[Results].Driver, dbo.RaceID.Site, dbo.[Results].LapsLed, dbo.[Results].Year, Right(dbo.[Results].RaceID,2) As RaceNo
FROM         dbo.[Results] INNER JOIN
dbo.RaceID ON dbo.[Results].RaceID = dbo.RaceID.RaceID
WHERE     (dbo.[Results].Year > 1999)
order by dbo.[Results].LapsLed desc;

ss5

In the select statement, I am selecting all the columns I want, including the Site name. Since there are columns from more than one table, we must specify the table name of each column.

Hope this helps!

Leave a Reply

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close