top | item 30819818

(no title)

qpiox | 3 years ago

There is nothing strange in this practice of only using a certain type of joins.

If you are right handed, and have a practice to write the joins in the direction one->many (or person->children, or in the opposite direction of a foreign key) then you will always write the join as:

from person join children

Then, if you are not a beginner and know a bit about nulls and their side-effects, the best thing that you can do to prevent the risk of missing data is:

from person left join children

Why? Because this will help so that you will never miss those persons that do not have children.

So, depending on the type of the application, it may be the case that outer joins are nearly always needed and it maybe be a part of quality assurance policies to always do a left join, so that most queries are easily readable by most of the team.

If you are left handed, then perhaps you will write the same query as:

from children right join person

full outer join is not needed at all if you have enforced referential integrity everywhere - you will only need a left (or right) outer join (depending on the left-to-right or right-to-left reading preference)

in databases that do not have referential integrity enforced on all true foreign keys, full outer join will probably be the only right type of join. Otherwise, you will have problems with many scenarios.

discuss

order

bryanrasmussen|3 years ago

Ok well I am right handed and that's how I would write it, but I figured that's cause I just don't know hardly any SQL.

Do you have any data on the handedness of people affecting the directing in which they write joins? It seems a strong enough assertion that somebody should have done research.

CraigJPerry|3 years ago

Not the OP but i doubt he literally meant left and right handed people. I read it as a fun, lighthearted way to differentiate two equally valid but opposing ways of thinking about the problems.