Kodewick
Start learning →
Mini challenge←→0 / 70

Oldest in Oslo

#066Mini challengeJOINORDER BY, LIMIT6 min

The vet is mailing check-up reminders for older pets in Oslo. Look only at pets whose owner's city is 'Oslo', sort by age from oldest, and keep the first 2. Pick three columns: the pet's name, the owner's name, and age.

The tables
owners
idnamecityphone
1LenaOslo555-0101
2MarcoRomeNULL
3PriyaOslo555-0103
4OmarCairoNULL
5SofiaRome555-0105
5 rows
pets
idnamekindageweightowner_id
1Biscuitdog3121
2Mochicat541
3Pepperdog8202
4Nemofish1NULL3
5Lunacat233
6Rexdog1130NULL
7Kiwibird4NULL5
8Tofucat75NULL
8 rows
query.sql
SELECT pets.name, owners.name, pets.age
FROM pets
JOIN owners ON pets.owner_id = owners.id
-- your code here: WHERE to keep Oslo, sort by pets.age from high to low, LIMIT 2
;
Ctrl + Enter runs too
Result

Run shows what your query gives. When it looks right, Submit.