3 ms·
Err, be careful with natural joins: suppose both tables have a column called "name" or "created_at" -- natural join will create join conditions from those.
by jessedhillon 11y ago
Err, be careful with natural joins: suppose both tables have a column called "name" or "created_at" -- natural join will create join conditions from those.
- marcosdumay 11y agoI never understood why the thing named "natural join" don't use relationships to determine the joining columns. Does not look natural for me.
- vog 11y agoIndeed, this is also what always annoyed me. I suspect that this has to do with the fact that NATURAL JOIN is intended to work for sub-SELECTs and VIEWs, too. On those, it is quite hard and error-prone to determine "foreign key" equivalents. Also note that restricting NATURAL JOINs to tables wouldn't be a good solution here, either, because that would prevent you from ever JOINing more than 2 tables: When JOINing 3 tables, you effectively do have some kind of sub SELECT after having joined the first two tables, which is then supposed to be joined with the third one.
- marcosdumay 11y agoYou get the same sort of problems jessedhillon was talking about. That is, you lose absolutely nothing - just changes its semantics.
- MichaelBurge 11y agoThat's why he said, "If you're feeling lucky".
- sjwright 11y agoWhich in the world of databases is a synonym for "useless". Typical boutique SQL query strings can be anything from a few to a few dozen lines and the compiled form is typically cached by the SQL engine (if you're using parameterised variables, which you are, because not doing so is stupid and dangerous). So why not be explicit?