ToolHop.

ADVERT

๐Ÿ—„๏ธ SQL Cheatsheet

SQL command reference for SELECT queries, filtering, joins, aggregation, schema changes, and performance tips.

SQL reference with dialect-aware snippets, in-page search, and a quick query builder for common SELECT workflows.

Query Builder

Generate a clean SELECT template and copy it into your editor.

SELECT id, customer_id, total FROM orders WHERE status = 'paid' ORDER BY created_at DESC LIMIT 50;

SELECT Essentials

Query patterns for projections and sorting.

QueryPurposeNotesCopy
SELECT id, email FROM users ORDER BY created_at DESC LIMIT 50;Sample dataLimit previews and avoid SELECT * in production endpoints.
SELECT DISTINCT country FROM orders;Unique valuesDISTINCT applies to the full set of selected columns.
SELECT * FROM events WHERE occurred_at >= NOW() - INTERVAL '7 days';Date filteringRelative date syntax varies by dialect.

Joins and Aggregations

Combine entities and summarize metrics.

QueryPurposeNotesCopy
SELECT o.id, c.name FROM orders o JOIN customers c ON c.id = o.customer_id;Inner joinReturns rows where both sides match the ON condition.
SELECT p.id, c.id FROM posts p LEFT JOIN comments c ON c.post_id = p.id;Left joinRetains parent rows when child rows are missing.
SELECT city, COUNT(*) AS total FROM users GROUP BY city HAVING COUNT(*) > 100;Group and HAVINGUse HAVING for aggregate filters after GROUP BY.

Schema and Write Patterns

DDL and mutation snippets used in migrations and services.

QueryPurposeNotesCopy
CREATE TABLE accounts ( id BIGSERIAL PRIMARY KEY, email TEXT UNIQUE NOT NULL, created_at TIMESTAMPTZ DEFAULT NOW() );Create tableDefine defaults and constraints up front.
INSERT INTO inventory (sku, qty) VALUES ($1, $2) ON CONFLICT (sku) DO UPDATE SET qty = EXCLUDED.qty;UpsertConflict syntax is dialect-specific.
BEGIN; UPDATE accounts SET balance = balance - 20 WHERE id = 1; COMMIT;TransactionProtect multi-step writes from partial failures.

ADVERT

ADVERT