Nen Bakraniya’s Post

I’ve reviewed a lot of SQL code over the years. The same 7 mistakes show up every time. In every company. At every level. 1. SELECT * — fetching 40 columns when you need 4. Every. Single. Time. 2. No indexes on JOIN keys — full table scan on every run. Your query isn’t slow. Your schema is. 3. Nested subqueries instead of CTEs — recalculated for every row. Rewrite it as a CTE. You’re welcome. 4. Never running EXPLAIN — optimising SQL without reading the execution plan is like driving blindfolded and guessing where the turns are. 5. Functions on WHERE columns — YEAR(date) = 2024 kills your index instantly. Use a date range. Two minutes to fix. Hours saved per run. 6. DISTINCT to hide bad JOINs — DISTINCT doesn’t fix duplicates. It hides them until someone asks why the revenue number looks wrong. 7. Filtering after the JOIN — joining 10 million rows then filtering to 50,000 is backwards. Filter first. Join small. I’ve committed all 7 at some point. Number 6 aged the worst. Which one made you wince? Drop your number below. #SQL #DataAnalytics #DataAnalyst #DataEngineering #OpenToWork

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories