Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dictionary database
Summary
9. Summary

Instruction

Incredible! Let's recap what we learned in this part.

You can join a table with itself. Each copy of the table must have an alias, and all column names must be prefixed with the corresponding table alias:

SELECT
  emp.name AS employee_name,
  supervisor.name AS supervisor_name
FROM employee AS emp
JOIN employee AS supervisor
  ON emp.supervisor_id = supervisor.id

As you may have guessed, you can combine self JOINs with other JOINs and SQL constructions.

Exercise

Select all data from the person table. It has five columns:

  • id – the ID of a given person,
  • name – the name of a given person,
  • mother_id – the ID of the person's mother,
  • father_id – the ID of the person's father, and
  • year_born – a given person's year of birth.

Stuck? Here's a hint!

Type:

SELECT *
FROM person