Question:
When is it best to use certain methods of joining tables?
How often asked: Constantly
Suggested by: ALittleMoron
Answer:
In most cases, INNER JOIN is used. It is most often used because it is often necessary to join tables with a complete intersection for a more precise answer without empty fields. LEFT/RIGHT JOIN is slightly less common. When the intersection is no longer absolutely important, you need to retrieve all the primary records in the desired primary table with additional context in the form of records from the second table. Depending on where the primary table is - left or right - we choose LEFT or RIGHT JOIN, but LEFT JOIN is usually chosen because the primary table, which is directly important for the result, usually comes first. It is easier for us to read from left to right, so the primary table comes on the left, and therefore LEFT JOIN is more often chosen. The remaining JOIN types, such as FULL JOIN, CROSS JOIN, and so on, are used much less frequently and are required for very specific scenarios, so they are not worth mentioning.
Interview answer explanation:
During an interview, the interviewer wants to understand the depth of a person's understanding of table join types and whether they can apply these skills where needed. This question doesn't require a deep understanding of how JOINs realy works in database engines, nor does it require you to know every JOIN possible in a database. The key is understanding the differences between basic JOINs, such as INNER/LEFT/RIGHT. Sometimes they clarify this question by asking how a LEFT OUTER JOIN differs from a LEFT JOIN, but that's a trick question. If the interviewer doesn't ask about the remaining JOINs, there's no point in wasting time on them.