Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Basic SQL Syntax  ›  Lesson

SQL Keywords and the Shape of a Statement

SQL Keywords 12 minKeywords are reserved words that mark each clause of a SQL statement, and the clauses of a query are always written in a fixed order.

SQL Keywords and the Shape of a Statement

The first time you read a real query it can look like a wall of capital letters. It is far less random than it looks: a handful of reserved words mark where each part of the statement begins, and they always appear in the same order. Learn the order once and every query becomes readable.

The rule

Keywords are SQL's grammar; everything else is a name you chose.

A keyword is a word with a fixed meaning to the database: SELECT, FROM, WHERE, CREATE, TABLE, ORDER, BY. Everything else in a statement is an identifier (a table or column name you created) or a value (like 'Pune' or 42).

SELECT name, city        -- keyword, then column names
FROM customers           -- keyword, then a table name
WHERE city = 'Pune'      -- keyword, then a condition
ORDER BY name;           -- keywords, then a column; ; ends the statement

A few rules follow from this:

  • Keywords are case-insensitive. select, SELECT and Select all work. Writing them in capitals is a convention that makes your own names stand out.
  • A statement ends with a semicolon. Some tools let you skip it for a single statement, but it is required to separate several.
  • Reserved words make poor names. A table called order clashes with the keyword ORDER, which is one reason tables are often plural, like orders.
  • Text values go in single quotes: 'Pune'. Double quotes, in standard SQL, are for identifiers.

Keywords also come in families by job. DDL (data definition) shapes tables: CREATE, ALTER, DROP, TRUNCATE. DML (data manipulation) works with rows: SELECT, INSERT, UPDATE, DELETE. DCL controls access: GRANT, REVOKE. TCL controls transactions: COMMIT, ROLLBACK.

The shortcut

The clauses of a query are always written in this order. Remember it as "Some Friendly Wizards Go Hunting Owls":

SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY

You may skip clauses, but never reorder the ones you use.

Reading an unfamiliar queryStep 1 of 3
  1. Find the keywords

    In SELECT city FROM customers WHERE joined_on > '2025-01-01' ORDER BY city; the keywords are SELECT, FROM, WHERE, ORDER BY.

A common mistake is writing WHERE after ORDER BY. The mnemonic catches it at once: Wizards come before Owls.

Drills

Answer fast — trust the rule.

quick drill

Which clause order is valid?

quick drill

Is select name from customers; a valid statement?

quick drill

Which of these is a DDL keyword?

quick drill

SELECT * FROM order; fails with a syntax error. What is the most likely cause?

Remember

  • Keywords are SQL's grammar; everything else is a name you chose.
  • Clause order: Some Friendly Wizards Go Hunting Owls — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.
  • Single quotes for text values; avoid reserved words as names.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRead a query aloud

Explain, part by part, what this statement asks for and which words are keywords versus names you chose: SELECT name, city FROM customers WHERE city <> 'Delhi' ORDER BY name;