Member-only story
Your SQL Query Works. Here’s Why It’s Still Slow.
A query that returns the right answer slowly is still a problem. Here are the most common reasons SQL queries underperform — and the fixes that actually help.
1. SELECT * Is Pulling Data You Don’t Need
Pulls every column across every row:
SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id;If you only need three columns, pulling thirty costs you memory, network transfer, and in columnar storage systems (like Databricks or BigQuery), unnecessary column scans.
Fix: Name your columns explicitly. Yes, it’s more typing, but it’s faster and more readable.
SELECT
orders.id AS order_id,
orders.order_date,
orders.total_amount,
customers.id AS customer_id,
customers.first_name,
customers.last_name,
customers.email
FROM orders
JOIN customers ON orders.customer_id = customers.id;────────────
2. You’re Filtering After Aggregating Instead of Before
— Slow: aggregates everything, then filters
SELECT customer_id, SUM(amount)
FROM orders
GROUP BY customer_id
HAVING customer_id > 1000;— Fast: filters first, then aggregates over smaller dataset











