


We use cookies to improve your experience
We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience.
8 sections · 51 items
| Code / Syntax | Description |
|---|---|
SELECT * FROM users | Select all columns from a table |
SELECT name, email FROM users | Select specific columns |
SELECT DISTINCT city FROM users | Select unique values only |
SELECT * FROM users LIMIT 10 | Limit results to 10 rows |
SELECT * FROM users LIMIT 10 OFFSET 20 | Skip 20 rows, then return 10 |
SELECT name AS full_name FROM users | Column alias |
| Code / Syntax | Description |
|---|---|
WHERE age = 25 | Equal to |
WHERE age != 25 or WHERE age <> 25 | Not equal to |
WHERE age > 18 | Greater than |
WHERE age >= 18 AND age <= 65 | Range with AND |
WHERE age BETWEEN 18 AND 65 | Range with BETWEEN (inclusive) |
WHERE name LIKE '%john%' | Pattern matching (% = any characters) |
WHERE name LIKE 'J___' | Pattern matching (_ = single character) |
WHERE city IN ('Paris', 'London', 'Berlin') | Match any value in list |
WHERE email IS NULL | Check for NULL |
WHERE email IS NOT NULL | Check for non-NULL |
| Code / Syntax | Description |
|---|---|
ORDER BY name ASC | Sort ascending (A-Z, default) |
ORDER BY created_at DESC | Sort descending (newest first) |
ORDER BY last_name, first_name | Sort by multiple columns |
GROUP BY city | Group rows by column value |
GROUP BY city HAVING COUNT(*) > 5 | Filter groups (like WHERE for groups) |
| Code / Syntax | Description |
|---|---|
INNER JOIN orders ON users.id = orders.user_id | Only matching rows from both tables |
LEFT JOIN orders ON users.id = orders.user_id | All from left + matching from right |
RIGHT JOIN orders ON users.id = orders.user_id | All from right + matching from left |
FULL OUTER JOIN orders ON users.id = orders.user_id | All rows from both tables |
CROSS JOIN colors | Every combination (cartesian product) |
users u JOIN orders o ON u.id = o.user_id | JOIN with table aliases |
| Code / Syntax | Description |
|---|---|
COUNT(*) | Count all rows |
COUNT(DISTINCT city) | Count unique values |
SUM(amount) | Sum of values |
AVG(price) | Average value |
MIN(created_at) | Minimum value |
MAX(score) | Maximum value |
| Code / Syntax | Description |
|---|---|
INSERT INTO users (name, email) VALUES ('Alice', '[email protected]') | Insert a row |
INSERT INTO users (name) VALUES ('A'), ('B'), ('C') | Insert multiple rows |
UPDATE users SET name = 'Bob' WHERE id = 1 | Update rows matching condition |
DELETE FROM users WHERE id = 1 | Delete rows matching condition |
TRUNCATE TABLE users | Delete all rows (fast, no rollback) |
| Code / Syntax | Description |
|---|---|
CONCAT(first, ' ', last) | Concatenate strings |
UPPER(name) | Convert to uppercase |
LOWER(name) | Convert to lowercase |
TRIM(name) | Remove leading/trailing whitespace |
LENGTH(name) or LEN(name) | String length |
SUBSTRING(name, 1, 3) | Extract substring (start, length) |
REPLACE(name, 'old', 'new') | Replace occurrences |
COALESCE(nickname, name, 'Unknown') | First non-NULL value |
| Code / Syntax | Description |
|---|---|
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100)) | Create table |
ALTER TABLE users ADD COLUMN age INT | Add column |
ALTER TABLE users DROP COLUMN age | Remove column |
DROP TABLE users | Delete entire table |
CREATE INDEX idx_email ON users(email) | Create index for faster lookups |