ORDER BY
ELI5 — The Vibe Check
ORDER BY sorts your query results. Add DESC for newest first, ASC for oldest first. Without ORDER BY, the database returns rows in whatever order it feels like — which is not always consistent.
Real Talk
ORDER BY sorts the result set by one or more columns in ascending (ASC, default) or descending (DESC) order. Sorting happens after WHERE and GROUP BY filtering. Without ORDER BY, the order of rows in a query result is not guaranteed by the database.
Show Me The Code
SELECT name, created_at
FROM users
ORDER BY created_at DESC, name ASC;
When You'll Hear This
"ORDER BY created_at DESC to show the newest users first." / "Don't rely on the default sort order — always specify ORDER BY."
Related Terms
GROUP BY
GROUP BY collapses rows with the same value into one group so you can count, sum, or average them. 'How many orders per user?' — GROUP BY user_id.
LIMIT
LIMIT caps how many rows a query returns. If your users table has 1 million rows, you do not want to load all of them at once.
SELECT
SELECT is how you ask a database to give you data. It is the 'Read' in CRUD.