Learn with Abdou

Chapter 2 · Concept 6 of 6 · Practice

Define what first and top mean

ORDER BY, DESC, ties, LIMIT and OFFSET · level 1 of 6

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Define what first and top mean · ORDER BY, DESC, ties, LIMIT and OFFSET · level 1 of 6

The three longest lines

Level 1: Watch it answered · Exercise 1 of 2

Which three lines are the longest in the whole table? Watch the query sort, break ties and stop at three, then run it.

Data: Rick & Morty.

Why it works, clause by clause

  1. No WHERE: the population is every line, whoever said it.
  2. ORDER BY wordCount DESC: the most words first. Without DESC the shortest lines would lead.
  3. , id: the tie-break. Two lines with the same count come out smaller id first, every run.
  4. LIMIT 3: keep the first three of that order, and only after the sort.

From the reading: Define what first and top mean, paragraph 1

The queryOpening the database…
SELECT id, characterName, wordCount
FROM scripts
ORDER BY wordCount DESC, id
LIMIT 3;
Open in the playground

Query results

Run it to see the result here.

Run it to see the result here.

Practice here is evidence for you and your instructor, never a grade. Grades live in Canvas.