I just found this piece of SQL code that returns the row that contains the oldest person:
Assume that you have a SQL table persons
with two columns, name
and age
:
SELECT p1.name, p1.age
FROM persons p1
LEFT JOIN persons p2 ON p1.age < p2.age
WHERE p2.age IS NULL
Why does this return the maximum? Although I think I know what the left join does, I don't get this example since it uses the same table twice.
Can someone explain what happens here? I really want to learn this.