Get to know the data
JOIN revisited
8. JOIN columns revised
LEFT JOIN
RIGHT JOIN
FULL JOIN
OUTER JOINS
NATURAL JOIN
Aliases for tables

Instruction

Very well!

You can select some columns in a JOIN query. Take a look at the example:

SELECT
  person.name, 
  car.brand, 
  car.model 
FROM person 
JOIN car
  ON person.id = car.owner_id;

Instead of all columns (select with the asterisk *) here we select only three columns: name from table person, brand from table car and model from table car.

We first put the name of the table, then a dot ., and then the name of the column we want to select.

Exercise

Join tables: student and room so that each student is shown together with the room they live in.

Select the name of the student and room number.

Stuck? Here's a hint!

Type:

SELECT
  student.name, 
  room.room_number 
FROM student 
JOIN room 
  ON student.room_id = room.id;