Real cases

Two of the ideas you practise, meeting in one real situation. Choose, see what actually happens, then reflect.

A case · you decide

Sorel and Capp find the top two

Capp & Sorel — a 16-year-old building a leaderboard page for a coding club

The idea in play: LIMIT takes the first N rows after ORDER BY has done its work.

The scores table has Ana 70, Ben 95, Cy 88, Di 60. The query is: SELECT name FROM scores ORDER BY score DESC LIMIT 2.

Sorel sorts: DESC puts the highest score first.

Capp takes the first two of those.

What does the query return?

Predict a query →

A case · you decide

Filo and Sole count the cities

Sole & Filo — a 17-year-old answering a club question about where members live

The idea in play: WHERE filters rows first; DISTINCT then folds repeats in the columns you selected.

The members table: Ana 15 Austin, Ben 17 Dallas, Cy 16 Austin, Di 18 Dallas, Ed 16 Houston. The query: SELECT DISTINCT city FROM members WHERE age >= 16.

Filo filters first: only the rows where age is 16 or more go on.

Sole folds repeats: each city that is left appears once.

How many rows does the query return?

Predict a query →