How to Share a SQL Query for Review (Formatting, Context and Safety)
Updated November 5, 2026 · 7 min read
A 60-line query pasted into chat as one long line is nearly impossible to review. The same query, formatted, with the table structure and an EXPLAIN plan, can often be fixed in minutes. Here's how to share SQL so the reviewer can actually help, without exposing real data.
Step 1: format it
Before:
select o.id,c.name,sum(i.qty*i.price) total from orders o join customers c on c.id=o.customer_id join order_items i on i.order_id=o.id where o.created_at>='2026-10-01' and o.status!='cancelled' group by o.id,c.name having sum(i.qty*i.price)>100 order by total desc
After:
SELECT
o.id,
c.name,
SUM(i.qty * i.price) AS total
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id
JOIN order_items AS i ON i.order_id = o.id
WHERE o.created_at >= '2026-10-01'
AND o.status <> 'cancelled'
GROUP BY o.id, c.name
HAVING SUM(i.qty * i.price) > 100
ORDER BY total DESC;
Conventions that help reviewers:
- One main clause per line; conditions indented under
WHERE. - Keywords in uppercase (or consistently lowercase); be consistent.
- Short aliases that mean something (
ofor orders, nott1). - One column per line in long
SELECTlists, so diffs and comments are clear.
Step 2: add the context
| Include | Why |
|---|---|
| Database and version | PostgreSQL, MySQL, SQL Server and SQLite differ in syntax and optimiser behaviour |
| Relevant table definitions | Column types and constraints explain many bugs |
| Indexes | The first thing to check for slow queries |
| Approximate row counts | A query fine on 1,000 rows may crawl on 10 million |
EXPLAIN output | Shows how the database actually runs the query |
| Expected vs actual result | "Returns 0 rows, should return about 40" |
Get the plan with EXPLAIN (MySQL), EXPLAIN ANALYZE (PostgreSQL, which also
runs the query) or "Display Estimated Execution Plan" (SQL Server). Plans are long, which is another
reason to share them as a link rather than in chat.
Step 3: remove real data
- Replace real emails, names and IDs in example values with fake ones.
- Share a handful of anonymised sample rows, not query results from production.
- Remove connection strings and credentials from any script you share (redaction checklist).
Step 4: share it as a link
- Open the code sharing tool.
- Paste the query, choose SQL, and add a title like "Monthly totals: slow on orders > 5M rows".
- Optionally create a second snippet for the EXPLAIN output and table definitions.
- Send the links with a one-sentence question.
Line numbers let reviewers comment precisely: "the join on line 7 needs an index on
order_items.order_id".
A message template
Question: this report query takes ~40s on production (PostgreSQL 16).
Query: https://sshot.online/c/Qy7Lm2a
EXPLAIN plan: https://sshot.online/c/Pn4Kx8d
Tables: orders (~5M rows), order_items (~18M), customers (~300k)
Indexes: orders(created_at), order_items(order_id)
Expected: under 2s for the dashboard
Common things reviewers spot
- Missing indexes on join and filter columns.
- Functions on indexed columns in
WHERE(for exampleDATE(created_at) = …), which can stop an index being used. SELECT *pulling far more data than needed.- Joins that multiply rows and inflate
SUMresults. - Comparisons with
NULLusing=instead ofIS NULL.
Paste your query, choose SQL, and share a link with line numbers and a raw view. Free, no account.
Frequently asked questions
How should I format a SQL query before sharing?
Put each main clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) on its own line, indent conditions, use uppercase keywords consistently, and give tables short, meaningful aliases.
What context helps someone review a slow query?
The table definitions or relevant columns, the indexes, approximate row counts, and the output of EXPLAIN (or EXPLAIN ANALYZE) for your database.
Is it safe to share query results?
Only after removing personal and confidential data. Share a few anonymised sample rows, never real customer records.
Why not paste SQL into chat?
Long queries lose indentation and get hard to discuss in chat. A snippet link keeps formatting and adds line numbers so reviewers can point to exact lines.
Related articles
How to Share Code Snippets Online Without Breaking the Formatting
Share code so indentation survives: why chat apps mangle code, how to share a clean link with line numbers and a raw view, how to choose between a snippet link, a gist and a screenshot, and what to remove first.
Read More →How to Format, Validate and Fix JSON (With Common Errors Explained)
Turn minified JSON into readable text, validate it, and fix the most common JSON errors: trailing commas, single quotes, unquoted keys and comments. Plus formatting in VS Code and on the command line.
Read More →How to Share a Config File Safely: A Redaction Checklist for .env, YAML and nginx
Share .env, YAML, JSON and nginx configs for debugging without leaking secrets: what to redact, consistent placeholders, examples, and what to do if a key was exposed.
Read More →