⚡ 100% In-Browser & Private: Your data never leaves your computer. Powered by Cloudflare Edge CDN.
ProWebTools PRO
Developer & SEO Utilities
SQL Matrix

Master SQL Query & Database Commands Cheat Sheet

Essential SQL database cheat sheet: SELECT, JOINS, GROUP BY, indexes, transactions, and performance profiling with 1-click copy.

Querying Data (SELECT) (6 commands)

Querying Data (SELECT)
SELECT * FROM users;

Retrieves all rows and columns from the specified table.

Querying Data (SELECT)
SELECT DISTINCT country FROM customers;

Filters out duplicate values and returns unique entries only.

Querying Data (SELECT)
SELECT id, email, status FROM accounts WHERE status = 'active' AND created_at >= '2026-01-01';

Filters rows according to one or more boolean criteria.

Querying Data (SELECT)
SELECT * FROM articles WHERE slug LIKE '%seo%';

Matches text using wildcards (% for zero or more, _ for single character).

Querying Data (SELECT)
SELECT name, price FROM products ORDER BY price DESC, name ASC;

Sorts rows in ascending (ASC) or descending (DESC) order by multiple columns.

Querying Data (SELECT)
SELECT * FROM audit_logs ORDER BY created_at DESC LIMIT 20 OFFSET 40;

Skips 40 rows and returns the subsequent 20 records (Page 3).

Aggregations & Grouping (3 commands)

Aggregations & Grouping
SELECT COUNT(*) AS total_users FROM users WHERE verified = true;

Returns the total number of matching rows.

Aggregations & Grouping
SELECT department_id, COUNT(*) AS headcount, AVG(salary) AS avg_sal FROM employees GROUP BY department_id;

Groups rows sharing common values into summary rows.

Aggregations & Grouping
SELECT customer_id, SUM(total_amount) AS total_spent FROM orders GROUP BY customer_id HAVING SUM(total_amount) > 1000;

Filters aggregated grouped results (unlike WHERE, which filters before aggregation).

Table Joins (3 commands)

Table Joins
SELECT u.name, o.id, o.amount FROM users u INNER JOIN orders o ON u.id = o.user_id;

Returns only records where the join key matches in both tables.

Table Joins
SELECT u.name, o.id AS order_id FROM users u LEFT JOIN orders o ON u.id = o.user_id;

Preserves all records from the left table even if right table has no matches (nulls).

Table Joins
SELECT o.id, u.email FROM users u RIGHT JOIN orders o ON u.id = o.user_id;

Preserves all records from the right table regardless of left table presence.

Data Modification (DML) (4 commands)

Data Modification (DML)
INSERT INTO products (name, sku, price, in_stock) VALUES ('Cloud CDN', 'CDN-01', 19.99, true);

Inserts one or more new rows into a database table.

Data Modification (DML)
UPDATE accounts SET tier = 'pro', updated_at = NOW() WHERE id = 142;

Modifies existing table data matching the predicate.

Data Modification (DML)
DELETE FROM sessions WHERE expires_at < NOW();

Removes records matching condition. Always include WHERE to prevent wiping table!

Data Modification (DML)
INSERT INTO user_settings (user_id, dark_mode) VALUES (42, true) ON CONFLICT (user_id) DO UPDATE SET dark_mode = EXCLUDED.dark_mode;

Inserts new row or updates existing row if unique constraint fails.

Schema & Indexing (DDL) (3 commands)

Schema & Indexing (DDL)
CREATE TABLE users ( id SERIAL PRIMARY KEY, email VARCHAR(255) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP );

Creates a new table with primary key, unique constraint, and default timestamp.

Schema & Indexing (DDL)
CREATE INDEX idx_orders_user_id ON orders(user_id);

Creates a B-Tree index on foreign key or frequently filtered column for $O(\log n)$ query lookup.

Schema & Indexing (DDL)
EXPLAIN ANALYZE SELECT * FROM transactions WHERE account_id = 9012 ORDER BY created_at DESC;

Outputs query execution plan, index scan vs seq scan, and exact millisecond timing.