Brightlane's customer success team is onboarding a new account manager who wants to review the most recent sign-ups first.
Write a query to return the ID, name, and email of the 5 most recently registered customers.
Assumptions:
- The
customerstable contains every customer Brightlane has on file. - The
created_atcolumn records when each customer registered.
Output:
- One row per customer, with columns
id,name, andemail, sorted bycreated_atdescending and capped at 5 rows.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
id,
name,
email
FROM
customers
ORDER BY
created_at DESC
LIMIT
5 The shape
Sorting created_at descending puts the newest registrations at the top of the result, and LIMIT 5 cuts the output at the row count the new account manager actually wants to see.
Clause by clause
SELECT id, name, emailpicks the three columns the briefing needs.FROM customersreads the full customer file. Filtering happens later in the pipeline.ORDER BY created_at DESCsorts so the most recentcreated_atcomes first. Descending flips "earliest first" into "most recent first." Tom Mann atid70 lands at the top — the most recently registered customer.LIMIT 5caps the output at five rows. PostgreSQL completes the sort, hands back the first five, and stops — every customer past Omar Jensen at row 5 is left out.
Why the sort matters
Without ORDER BY, LIMIT 5 would still return five rows, but which five would be up to the execution plan. Run the query twice and the result could change. Pairing LIMIT with ORDER BY created_at DESC is what turns "five rows" into "the five most recent rows" — a sort key matched to the question the account manager is asking.
You practiced capping a sorted result set with LIMIT. LIMIT is the recurring shape behind every "top N" or "most recent N" query — it operates on whatever order ORDER BY produced, so the sort key is what makes the cap meaningful.