How I Debug JOIN Issues at Work
Welcome to **Day 44**. Joins are where 80% of SQL bugs happen. Here is my personal checklist for debugging them.
1. Check the Row Count
Before joining, run `SELECT COUNT(*)` on both tables. If Table A has 100 rows and the result has 500, you have a duplicate problem.
2. Verify the Join Column
Run this query:
SELECT column_name, COUNT(*)
FROM table
GROUP BY column_name
HAVING COUNT(*) > 1;
If this returns anything, your "ID" isn't unique, which is why your join is duplicating data.
3. The "LIMIT 10" Test
If a join is slow, don't wait for it to finish. Add `LIMIT 10` and see if it returns *anything*. If it does, your logic is okay, but your performance is bad (probably missing an index).
4. Check for NULL IDs
If your join returns zero rows but you're sure they match, check for NULLs or hidden spaces in your ID columns!
Your Task for Today
Apply this checklist to the most complex join you currently have in your project.
*Day 45: Real Project—Multi-Table Reporting Query.*