Databases · SQL Operations
JOINs
Cheat sheet · https://pcornel.dk/topic.php?topic=6165
Answer
JOINs combine rows from tables on a condition: INNER (matching rows), LEFT/RIGHT (keep one side), FULL (both), CROSS (all combinations).
Remember
Missing join conditions create row explosions. LEFT JOIN filters in WHERE turn it into an INNER JOIN — put them in ON. Index join columns.
First checks
EXPLAIN— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
Verify in this order
tables → join condition → matched rows → result
Where it usually breaks
Joining two one-to-many tables at once inflates sums (fan-out).
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6165