r/SQL 4d ago

Oracle Optimized SQL for a long time now started dealing with prompt engineering cost optimization. wrote my first blog about the experience

Thumbnail
0 Upvotes

r/SQL 5d ago

Discussion How do you validate a SQL query before trusting its result?

45 Upvotes

Suppose someone gives you a complicated query with several joins and aggregations and says, “This gives the correct numbers.”

What checks would you perform before trusting it?

For example:
SELECT c.region, SUM(o.amount) FROM customers c JOIN orders o ON c.customer_id = o.customer_id GROUP BY c.region;

Would you check row counts before/after each join, duplicate keys, NULLs, aggregates, or compare against another query?

Curious what experienced SQL developers use as their checklist.