SQL Keywords

A clean, quick-lookup list of core SQL keywords grouped by intent (querying, filtering, joins, aggregation, DDL, DML, transactions). Short explanations + tiny examples.

On this page

What this page is

This is a practical keyword index for fast recall. Syntax varies by database; examples are ANSI-style unless noted.

Query structure

  • SELECT – choose columns/expressions
  • FROM – source tables/views/subqueries
  • WHERE – row filtering (before grouping)
  • GROUP BY – group rows for aggregates
  • HAVING – filter groups (after grouping)
  • ORDER BY – sort result
  • LIMIT/TOP/FETCH – restrict row count (vendor-specific)

Joins

  • JOIN/INNER JOIN – matching rows only
  • LEFT JOIN – keep all left rows, match right when possible
  • RIGHT JOIN – keep all right rows (less common)
  • FULL OUTER JOIN – keep both sides (not in MySQL; use UNION workaround)
  • CROSS JOIN – cartesian product
SELECT o.id, c.name
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'paid';

Filtering and predicates

  • AND, OR, NOT – boolean logic
  • IN – membership check
  • BETWEEN – inclusive range
  • LIKE – pattern match (%, _)
  • IS NULL/IS NOT NULL – null checks
  • EXISTS – subquery existence
SELECT *
FROM products
WHERE price BETWEEN 10 AND 50
  AND name LIKE '%pro%'
  AND discontinued IS NULL;

Aggregation

  • COUNT, SUM, AVG, MIN, MAX – aggregate functions
  • DISTINCT – unique values
SELECT customer_id, COUNT(*) AS order_count
FROM orders
GROUP BY customer_id
HAVING COUNT(*) >= 5
ORDER BY order_count DESC;

Set operations

  • UNION – merge distinct rows
  • UNION ALL – merge including duplicates
  • INTERSECT – common rows (vendor-specific)
  • EXCEPT/MINUS – rows in first but not second (vendor-specific)

Subqueries and derived tables

  • AS – alias
  • WITH – common table expression (CTE)
WITH recent AS (
  SELECT id, customer_id
  FROM orders
  WHERE created_at >= '2026-01-01'
)
SELECT customer_id, COUNT(*) AS n
FROM recent
GROUP BY customer_id;

DDL (schema)

  • CREATE, ALTER, DROP – create/change/remove objects
  • TABLE, VIEW, INDEX, DATABASE – object types
  • PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK – constraints
  • DEFAULT, NOT NULL – column rules
CREATE TABLE users (
  id INT PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

DML (data changes)

  • INSERT – add rows
  • UPDATE – modify rows
  • DELETE – remove rows
UPDATE users
SET email = 'new@example.com'
WHERE id = 10;

Transactions

  • BEGIN/START TRANSACTION
  • COMMIT
  • ROLLBACK
  • SAVEPOINT
START TRANSACTION;
UPDATE accounts SET balance = balance - 50 WHERE id = 1;
UPDATE accounts SET balance = balance + 50 WHERE id = 2;
COMMIT;

Handy notes

  • WHERE vs HAVING: WHERE filters rows; HAVING filters groups.
  • NULL is not equal to anything (even another NULL). Use IS NULL.
  • Join condition belongs in ON; row filters belong in WHERE (most of the time).