Do you always have to join tables on their id? SQL

Just wondering because I’m always doing it.

You can join tables on any field that you like depending on the context. As long as the field is in both tables and is a unique identifier in one of those tables, then it’s completely fine to join on that. However generally you cannot always predict if something will be a unique identifier or not and that’s what you add an id field, so that every row in a table can always be uniquely identified.


It might be helpful to read up on PRIMARY and FOREIGN keys.

and, here:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.