i have one confusion in joins, whenever we want to join two tables assume T1 and T2, and give a LEFT JOIN, which one is the left table, and which one is the right table.
Hi TJ, thanks for the great Question! If we write "SELECT ... FROM T1 LEFT JOIN T2 ON ..." then T1 is the left table because it is written BEFORE the LEFT JOIN Statement. T2 is the right table because it is written AFTER the LEFT JOIN Statement.
Hi abinash, I disagree, the 2nd Query is correct, you can see it passing at 25:41. I also did the second query because it is a more general solution than the first one
Why can't I LEFT JOIN all of them based on Company_code since they are all linked to the company code ? Its confusing when more than one foreign key exist
Hi Amgd, thanks I haven't thought about that! You can do that and it is also the best solution because you are not assuming any relationships of subordinate/superior in the company. Thanks for your input! I published the solution with all tables linked to company code here: github.com/MarkusFriemann/HackerRank/blob/main/New%20Companies
Hi Arman, logically you are right. It depends on what kind of SQL you are using. MSSQL requires you to always Group by all the non-aggregated columns. Because we are printing company_code and founder, we also have to group by these columns. In MySQL the solution would work with only grouping by company_code.