Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
How to query more than one table
Creating JOINs
Referencing columns
7. Display specific columns
Let's practice

Instruction

Splendid! Now, let's say we only need a few columns in our result. We just want to know the model of each car and its owner's name. Take a look:

SELECT
  Person.Name,
  Car.Model
FROM Person
JOIN Car
  ON Person.Id = Car.OwnerId;

Simple, isn't it? Instead of the asterisk (*), we list the column names.

As we now have more than one table, we put the table name in front of the column name and we separate them with a dot (.). In this way, T-SQL knows that the Model column belongs to the car table, amd so on.

Exercise

Select the director name and movie title from the tables Movie and Director such that each movie is shown together with its director.

Stuck? Here's a hint!

Type:

SELECT
  Movie.Title,
  Director.Name
FROM Movie
JOIN Director
ON Movie.DirectorId = Director.Id;