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 EmployeeName,
  Supervisor.Name AS SupervisorName
FROM Employee AS Emp
JOIN Employee AS Supervisor
  ON Emp.SupervisorId = 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,
  • MotherId – the ID of the person's mother,
  • FatherId – the ID of the person's father, and
  • YearBorn – a given person's year of birth.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Person