What is the difference between an INNER JOIN and a LEFT JOIN in SQL?
a) INNER JOIN returns only matching rows, LEFT JOIN returns all rows from the left table
b) LEFT JOIN returns only matching rows, INNER JOIN returns all rows from the left table
c) INNER JOIN is faster than LEFT JOIN
d) LEFT JOIN does not allow NULL values
Answer:
a) INNER JOIN returns only matching rows, LEFT JOIN returns all rows from the left table
Explanation:
An INNER JOIN returns only the rows where there is a match between the two tables being joined. If there is no match, the row is excluded from the result set.
A LEFT JOIN returns all rows from the left table and the matching rows from the right table. If there is no match, NULL values are returned for the columns of the right table.
LEFT JOIN is used when you want to keep all records from the left table regardless of whether they have matching rows in the right table, while INNER JOIN is used when you only need the records that exist in both tables.