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.DateAdded < Item2.DateAdded
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'