Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Medical Center database
Non primary-foreign key JOINs
Non-equi JOINs
Non-equi self JOINs
20. Employee ages
Summary

Instruction

Good! We can also use non-equi JOINs in order to, for example, list items added after a particular item or date:

SELECT
  item1.name
FROM items item1
JOIN items item2
  ON item1.date_added < item2.date_added
WHERE item2.id = 3

With this query, we limit the aliased item2 table to only one record (with id = 3) and tell our database to show the names of all items that were added before the item with id = 3.

Exercise

Show the names of all employees who are younger than Mark Gatis.

Stuck? Here's a hint!

Type:

SELECT
  emp1.name
FROM employee emp1
JOIN employee emp2
  ON emp1.age < emp2.age
WHERE emp2.name = 'Mark Gatis'