|
|
|
|
|
by kbenson
2985 days ago
|
|
This is good advice, IMO. You will have to use left/right joins at some point, and having the join type at the join location is useful, but having the join conditions at the join location is immensely useful. It's harder to see in your example, likely because you tried to keep it similar to the example presented, but once there's more than a couple joins, having the join conditions close to the join is essential for keeping track of what's going on. e.g. SELECT * FROM person, team, role, group, person AS lead
WHERE person.team_id=team.id
AND person.role_id=role.id
AND person.group_id=group.id
AND group.lead_id=lead.id
Compared to: SELECT * from person
INNER JOIN team ON person.team.id=team.id
INNER JOIN role ON person.role_id=role.id
INNER JOIN group ON person.group_id=group.id
INNER JOIN person AS lead ON group.lead_id=lead.id
And let's be clear, we know these should be left joins, because the chance some person doesn't have a team, role, group, or a group ends up without a lead is high when sampled over time. And simulating left joins with the non-ANSI joins quickly gets unwieldy. |
|