What is the difference between INNER JOIN and LEFT JOIN?

Answer

INNER JOIN returns only rows where the join condition matches in both tables. Rows without a match in either table are excluded. LEFT JOIN (also LEFT OUTER JOIN) returns all rows from the left (first) table, plus matching rows from the right table. Where there is no match, the right table's columns are filled with NULL. Use LEFT JOIN when you want to include records from the left table regardless of whether a related record exists in the right table. Example: finding all users even those with no orders: SELECT u.name, o.id FROM users u LEFT JOIN orders o ON u.id = o.user_id; — users with no orders appear with o.id = NULL.