Select All Columns
SELECT * FROM users;Returns every column and row from a table.
SQL syntax quick reference for queries, joins and table changes, based on the official PostgreSQL documentation. Every item below is clearly marked as a shortcut, command, or syntax reference.
SELECT * FROM users;Returns every column and row from a table.
SELECT * FROM users WHERE age > 30;Returns only rows matching a condition.
SELECT * FROM orders o
JOIN users u ON u.id = o.user_id;Returns rows with matches in both tables.
INSERT INTO users (name, email)
VALUES ('Ada', 'ada@example.com');Adds a new row to a table.
SELECT name, email FROM users;Returns only the columns you name.
SELECT * FROM users ORDER BY created_at DESC;Orders rows by one or more columns.
SELECT * FROM users LIMIT 10;Returns only the first N rows.
SELECT COUNT(*) FROM users;Counts the number of rows.
Returns every column and row from a table.
SELECT * FROM users;Returns only rows matching a condition.
SELECT * FROM users WHERE age > 30;Returns rows with matches in both tables.
SELECT * FROM orders o
JOIN users u ON u.id = o.user_id;Adds a new row to a table.
INSERT INTO users (name, email)
VALUES ('Ada', 'ada@example.com');Returns only the columns you name.
SELECT name, email FROM users;Orders rows by one or more columns.
SELECT * FROM users ORDER BY created_at DESC;Returns only the first N rows.
SELECT * FROM users LIMIT 10;Counts the number of rows.
SELECT COUNT(*) FROM users;Aggregates rows per group.
SELECT country, COUNT(*) FROM users GROUP BY country;Returns all left rows plus matches from the right.
SELECT * FROM users u
LEFT JOIN orders o ON o.user_id = u.id;Changes values in existing rows.
UPDATE users SET active = false WHERE id = 7;Removes rows from a table.
DELETE FROM users WHERE id = 7;Creates a new table with columns.
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);Filters with AND / OR.
WHERE country = 'US' AND active = trueFilters text with wildcards.
WHERE name LIKE 'A%'Returns only unique values.
SELECT DISTINCT country FROM users;Aggregates a numeric column.
SELECT SUM(total), AVG(total), MIN(total), MAX(total) FROM orders;Adds a column to an existing table.
ALTER TABLE users ADD COLUMN phone TEXT;Filters by a list of values.
WHERE id IN (1, 2, 3)Finds rows where a value is missing.
WHERE email IS NULLGives a column or expression an alias.
SELECT name AS full_name FROM users;Filters groups after aggregation.
GROUP BY country HAVING COUNT(*) > 5Uses one query's results inside another.
SELECT * FROM users
WHERE id IN (SELECT user_id FROM orders);Returns values based on conditions.
CASE WHEN total > 100 THEN 'big' ELSE 'small' ENDRemoves a table and all its data.
DROP TABLE users;Speeds up lookups on a column.
CREATE INDEX idx_users_email ON users (email);Filters values inside a range (inclusive).
WHERE price BETWEEN 10 AND 20Stacks results of two queries, removing duplicates.
SELECT email FROM a
UNION
SELECT email FROM b;Names a temporary result set with WITH.
WITH recent AS (
SELECT * FROM orders WHERE created_at > now() - interval '7 days'
)
SELECT * FROM recent;Removes a column from a table.
ALTER TABLE users DROP COLUMN phone;Removes all rows quickly.
TRUNCATE TABLE logs;Links a column to another table.
ALTER TABLE orders
ADD FOREIGN KEY (user_id) REFERENCES users (id);Groups statements so they all succeed or fail.
BEGIN;
...
COMMIT; -- or ROLLBACK;Returns the first non-null value.
COALESCE(phone, 'n/a')Renames an existing table.
ALTER TABLE users RENAME TO members;Saves a query as a virtual table.
CREATE VIEW active_users AS
SELECT * FROM users WHERE active;It covers 36 common SQL patterns and examples, including Select All Columns, Filter Rows with WHERE, Inner Join, Insert a Row, Select Specific Columns.
Yes. Each reference page includes a copyable code example.
Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.