SQL syntax
Good SQL is rarely about clever tricks.
Most of the time, it is about getting structure right: what to select, where it comes from, how it is filtered, and how it is ordered.
Think in Clauses, Not in One Long Sentence #
A query is built from clauses.
Each clause has a job, and clauses are easier to reason about when you read them as building blocks instead of as one giant statement.
Core Clauses You Will Use Every Day #
| Clause | Purpose |
|---|---|
| SELECT | Choose columns to return |
| FROM | Choose source table(s) |
| WHERE | Filter rows before grouping |
| GROUP BY | Aggregate by key(s) |
| HAVING | Filter after aggregation |
| ORDER BY | Sort final output |
| LIMIT | Restrict row count |
SELECT column_list
FROM table_name
WHERE condition
GROUP BY grouping_columns
HAVING aggregate_condition
ORDER BY sort_columns
LIMIT n;Why Clause Order Feels Weird at First #
SQL is written in one order and evaluated in another.
That mismatch is normal, and understanding it will prevent a lot of confusion:
FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> ORDER BY -> LIMIT
This mental model helps explain many beginner errors, especially around aggregation and filtering.
Run and Tweak #
Run this query, then change one clause at a time to see how the output changes:
Knowledge check #
3 questions
Which of these is the standard clause order when writing a query?
SQL keywords like
SELECTandFROMare:How do you write a single-line comment in SQL?
Next Step #
Continue to SQL datatypes to understand how value types affect filtering, sorting, and calculations.