🔍
👶 Kids📝 Blog About Contact 🚀 Get Started Free

SQL – Syntax

Master the fundamental syntax rules of SQL — keywords, clauses, whitespace, and best practices.

SQL has a clean, consistent structure that you will master quickly. Every SQL statement is built from clauses — named blocks that perform a specific role. The SELECT clause picks columns, FROM names the table, WHERE filters rows, and ORDER BY sorts results. Clauses are always written in a specific order, though most of them are optional.

One important thing: SQL keywords are case-insensitive. Writing select is identical to SELECT. However, capitalizing keywords is a widely adopted convention that makes queries far easier to read at a glance — always write SELECT, not select.

SQL Statement Anatomy

SELECT column1, column2   -- What to show
FROM   table_name          -- Where to look
WHERE  condition           -- Which rows to include
ORDER  BY column ASC/DESC  -- How to sort results
LIMIT  n;                  -- How many rows to return

Try It Yourself — Interactive SQL Editor

Edit the query below and click Run Query ▶ to see live results powered by SQLite running directly in your browser.

SQLite – edit & run
Results
← Click Run Query ▶ to see results

Key Points

  • SQL is not case-sensitive for keywords, but capitalize by convention
  • Statements end with a semicolon (;)
  • Whitespace and line breaks are ignored — format for readability
  • Comments use — for single line or /* */ for multi-line

Pro Tip from CodesCompiler: The best way to learn SQL is to break things intentionally — modify the query above, change the WHERE conditions, try different columns. Every error teaches you something the docs cannot.

In the next lesson, we continue exploring SQL’s powerful feature set to build your database mastery.