Medical Center database
Non primary-foreign key JOINs
Non-equi JOINs
18. Preferred affordable apartments
Non-equi self JOINs
Summary

Instruction

Amazing! How about this one?

Exercise

For each couple that has an apartment, show their name, apartment ID, and location for all apartments that are within their price range and in their preferred location.

Stuck? Here's a hint!

Type:

SELECT
  couples.couple_name,
  apartments.id,
  location
FROM couples
JOIN apartments  
  ON apartments.price BETWEEN couples.min_price AND couples.max_price
WHERE apartments.location = couples.pref_location

Console

Code editor

Result

TableConsole