Introduction
Dictionary database
Summary
10. Person table – exercise 1

Instruction

Good! Let's try the first exercise with the person table.

Exercise

Show the name of each person (name the column child_name) together with the name of their mother (name the column mother_name). Include all people even those for whom there is no information about their mother.

Stuck? Here's a hint!

Type:

SELECT
  child.name  AS child_name,
  mother.name AS mother_name
FROM person AS child
LEFT JOIN person AS mother
  ON child.mother_id = mother.id

Console

Code editor

Result

TableConsole