| Command | Description | Syntax | Example |
|---|---|---|---|
| AS (Aliases) | Gives columns or tables a temporary name for readability. | SELECT col AS alias |
SELECT employee_name AS "Staff Name" |
| SELECT TOP / LIMIT | Restricts the number of rows returned. | SELECT TOP (n) | LIMIT n; |
SELECT * FROM sales_logs |
| Command | Description | Syntax | Example |
|---|---|---|---|
| AND / OR | Used to filter records based on more than one condition. | SELECT col |
SELECT * FROM employees |
| BETWEEN | Filters values within a given range (inclusive). | WHERE col |
SELECT * FROM orders |
| LIKE / ILIKE | Pattern matching. % is a wildcard. ILIKE is case-insensitive. | WHERE col LIKE 'pattern'; |
WHERE email LIKE '%@gmail.com'; |
| ANY / ALL | "ANY" returns true if any subquery values meet the condition; "ALL" requires all to meet it. | SELECT col |
SELECT name FROM products |
| Command | Description | Syntax | Example |
|---|---|---|---|
| CASE | Handles conditional logic (IF-THEN-ELSE). | CASE |
SELECT product_name, |
| Command | Description | Syntax | Example |
|---|---|---|---|
| CONCAT | Joins multiple strings into one. | CONCAT(s1, s2, ...); |
SELECT CONCAT(first_name, ' ', last_name) AS "Full Name" |
| Command | Description | Syntax | Example |
|---|---|---|---|
| EXTRACT | Extracts a portion of a date (Year, Month, Day, etc.). | SELECT EXTRACT(part FROM col); |
SELECT EXTRACT(month FROM hire_date) AS "Hire Month" |
| Command | Description | Syntax | Example |
|---|---|---|---|
| AVG() | Returns the average value of a numeric column. | SELECT AVG(col) |
SELECT AVG(unit_price) |
| COUNT | Returns the number of rows matching the criteria. | SELECT COUNT(col) FROM table; |
SELECT COUNT(customer_id) FROM orders; |
| MAX() / MIN() | Returns the largest or smallest value. | SELECT MAX|MIN(col) FROM table; |
SELECT MAX(salary) FROM employees; |
| Command | Description | Syntax | Example |
|---|---|---|---|
| GROUP BY | Groups rows sharing the same values into summary rows. | SELECT col, aggregate(col) |
SELECT region, SUM(sales_total) |
| HAVING | Filters groups (used instead of WHERE for aggregates). | SELECT col FROM table |
SELECT category, COUNT(*) |
| Command | Description | Syntax | Example |
|---|---|---|---|
| JOINS | Combines rows from tables based on a related column. | SELECT * FROM T1 |
SELECT orders.id, customers.name |
| Command | Description | Syntax | Example |
|---|---|---|---|
| Math (+, -, *, /) | Performs calculations on numeric data. | SELECT col1 * col2; |
SELECT (price * quantity) AS "Total Revenue" |
| Command | Description | Syntax | Example |
|---|---|---|---|
| CREATE TABLE | Creates a new table in the database. | CREATE TABLE table ( |
CREATE TABLE inventory ( |
| ALTER TABLE | Adds, deletes, or modifies columns in an existing table. | ALTER TABLE table |
ALTER TABLE customers |
| Command | Description | Syntax | Example |
|---|---|---|---|
| UPDATE | Modifies existing records in a table. | UPDATE table |
UPDATE products SET price = 19.99 |
| DELETE | Deletes specific rows. Caution: Omitting WHERE deletes all data. | DELETE FROM table |
DELETE FROM customers |