3 ms·
> If there was no director in the database then this query would return 0 rows. Well, LEFT JOIN is the basic SQL knowledge, surprising the author doesn't know
by deepsun 1y ago
> If there was no director in the database then this query would return 0 rows.
Well, LEFT JOIN is the basic SQL knowledge, surprising the author doesn't know that.
> because sql wasn't designed to produce hierarchical data
Well, SQL was designed _because_ of the shortcomings of hierarchical DBMSes.
Also, author uses PostgreSQL, so could easily use ARRAY_AGG(), and Composite Types to get the exact answer they need in one query, no need for hacks. They can even make their own custom type for type safety, if needed.
- School-Cotton 1y agoI promise Jamie Brandon knows about left joins.
- mcdonje 1y agoSo then it's a bad faith example.
- School-Cotton 1y agoI'm not Jamie but I think the point is just that this is an awkward way to represent one-to-many relationships. Even with left joins things are even clunkier because you no longer have the clunky but straightforward n * m formula for number of rows, you have something even more confusing: n * max(1, m)