Introduction
3. JOIN - revision
Foreign keys
Multicolumn foreign keys
Updates and deletes
Revision

Instruction

Excellent. Both tables are already present in our database. We've put some data into them as well.

Do you remember how to retrieve data from multiple tables in SQL queries? That's right, we used JOINs. See the example:

SELECT * 
FROM project 
JOIN employee ON project.manager_id = employee.id;

The above query will select all information from the table project and all the information from the table employee. The information from both tables will be joined together thanks to columns employee.id and project.manager_id.

Exercise

Use JOIN to select name and manager_id (table project) together with the last name of its the manager (table employee).

Stuck? Here's a hint!

Type

SELECT project.name, project.manager_id, employee.last_name 
FROM project 
JOIN employee 
ON project.manager_id = employee.id;

Console

Code editor

Result

TableConsole