Consider table a with 3 records with id column primary key with values 1, 2, 3. Consider table b with 6 records with a_id as foreign key with values 1, 2, 3, 3, 3, 3. How many records b left join a and a left join b query would return?
Answers
Left join would always return all the records from the left side table and matching records from the right side table. There will be a null value of the right side table if no matches are found.
Syntax:
SELECT list of columns
FROM table1
LEFT JOIN table2
ON table1.col_name = table2.col_name;
Case 1: All the records from b would be displayed; the values with matches will have value fetched from both the tables. The rows which are not common will be displayed from the left-side table (b) and a null for columns in table (a).
Case 2: All the records from “a” would be displayed; the values with matches will have value fetched from both the tables. The rows which are not common will be displayed from the left-side table (a) and a null for columns in table (b).
Answer:
6 6
Explanation: