I got this question in one of the interviews asking about left and right joins in Mysql.
Why do we need Left join when there is already right and vice a versa?
Explanation:-
SELECT * FROM users LEFT JOIN profile ON (users.user_id= profile.user_id);
This will result is all matching data of profile table and all data of users table. Now what I do is do the same thing using RIGHT JOIN.
SELECT * FROM profile RIGHT JOIN users ON(profile.user_id = users.user_id)
This will also have the same result as of above query i.e what I did here is moved the left table to right and made the join from left to right table.
Now when I can perform this using left Join and also I can do the same using right Join. Is there any need to both the Joins or we can do everything using one JOIN only i.e either left or right.
I will be very thankful to get help of anyone who knows and can explain me the same.
Thanks in advance.