SELECT: SELECT first_name, last_name FROM employees; : Retrieve specific columns from a table
SELECT *: SELECT * FROM products; : Fetch all columns quickly when exploring data
DISTINCT: SELECT DISTINCT country FROM customers; : Return unique values, removing duplicates
FROM (sub-query): SELECT * FROM (SELECT * FROM sales WHERE year=2025) AS y25; : Treat a derived table as input
AS (alias): SELECT price AS unit_price FROM sales; : Rename columns or tables for readability
Literals: SELECT 'John' AS name, 123 AS num, NULL AS nothing; : Embed constant values directly in query
Expression (arith): SELECT price*qty AS total FROM order_items; : Compute new values on the fly
ORDER BY: SELECT * FROM students ORDER BY score DESC; : Sort result rows in a defined order
ASC / DESC: SELECT * FROM flights ORDER BY depart_dt ASC; : Specify ascending or descending sort direction
LIMIT: SELECT * FROM logs LIMIT 100; : Restrict output to first N rows for sampling
OFFSET: SELECT * FROM logs LIMIT 50 OFFSET 100; : Skip rows, useful for pagination
FETCH FIRST: SELECT * FROM employees ORDER BY hire_date FETCH FIRST 5 ROWS ONLY; : Standard SQL way to limit rows
TOP (T-SQL): SELECT TOP 10 * FROM Customers; : SQL Server syntax to fetch first N rows
User Variable: SET @row_num:=0; SELECT @row_num:=@row_num+1 AS n, name FROM people; : Store and reuse values within session
USE (DB): USE sakila; : Switch current database context
SHOW DATABASES: SHOW DATABASES; : List databases present on the server
SHOW TABLES: SHOW TABLES FROM sakila; : List tables in a database
DESCRIBE / DESC: DESC employees; : Display table schema quickly
EXPLAIN: EXPLAIN SELECT * FROM sales WHERE id=1; : Inspect execution plan for performance tuning
HELP: HELP SELECT; : Get built in MySQL documentation for a keyword
COMMENT in DDL: CREATE TABLE t(id INT COMMENT 'Primary key'); ?: Attach human-readable notes to schema objects
Inline Comments: : Single line comment : Document code or disable lines during testing
FORCE INDEX(): SELECT * FROM t FORCE INDEX(idx_col) WHERE col=1; : Override optimizer to use a specific index
SQL_MODE: SET sql_mode='STRICT_ALL_TABLES'; : Change SQL behavior (e.g. strictness) for the session
SELECT INTO OUTFILE: SELECT * FROM employees INTO OUTFILE '/tmp/emp.csv' FIELDS TERMINATED BY ','; : Export query result to an external file
SELECT *: SELECT * FROM products; : Fetch all columns quickly when exploring data
DISTINCT: SELECT DISTINCT country FROM customers; : Return unique values, removing duplicates
FROM (sub-query): SELECT * FROM (SELECT * FROM sales WHERE year=2025) AS y25; : Treat a derived table as input
AS (alias): SELECT price AS unit_price FROM sales; : Rename columns or tables for readability
Literals: SELECT 'John' AS name, 123 AS num, NULL AS nothing; : Embed constant values directly in query
Expression (arith): SELECT price*qty AS total FROM order_items; : Compute new values on the fly
ORDER BY: SELECT * FROM students ORDER BY score DESC; : Sort result rows in a defined order
ASC / DESC: SELECT * FROM flights ORDER BY depart_dt ASC; : Specify ascending or descending sort direction
LIMIT: SELECT * FROM logs LIMIT 100; : Restrict output to first N rows for sampling
OFFSET: SELECT * FROM logs LIMIT 50 OFFSET 100; : Skip rows, useful for pagination
FETCH FIRST: SELECT * FROM employees ORDER BY hire_date FETCH FIRST 5 ROWS ONLY; : Standard SQL way to limit rows
TOP (T-SQL): SELECT TOP 10 * FROM Customers; : SQL Server syntax to fetch first N rows
User Variable: SET @row_num:=0; SELECT @row_num:=@row_num+1 AS n, name FROM people; : Store and reuse values within session
USE (DB): USE sakila; : Switch current database context
SHOW DATABASES: SHOW DATABASES; : List databases present on the server
SHOW TABLES: SHOW TABLES FROM sakila; : List tables in a database
DESCRIBE / DESC: DESC employees; : Display table schema quickly
EXPLAIN: EXPLAIN SELECT * FROM sales WHERE id=1; : Inspect execution plan for performance tuning
HELP: HELP SELECT; : Get built in MySQL documentation for a keyword
COMMENT in DDL: CREATE TABLE t(id INT COMMENT 'Primary key'); ?: Attach human-readable notes to schema objects
Inline Comments: : Single line comment : Document code or disable lines during testing
FORCE INDEX(): SELECT * FROM t FORCE INDEX(idx_col) WHERE col=1; : Override optimizer to use a specific index
SQL_MODE: SET sql_mode='STRICT_ALL_TABLES'; : Change SQL behavior (e.g. strictness) for the session
SELECT INTO OUTFILE: SELECT * FROM employees INTO OUTFILE '/tmp/emp.csv' FIELDS TERMINATED BY ','; : Export query result to an external file