InterviewHubPRO
Section Overview
Q15

Question 15 of 60

Part 2: Relational Databases (RDBMS / PostgreSQL / MySQL) (6 - 25)

25%
Databases & System Design•Part 2: Relational Databases (RDBMS / PostgreSQL / MySQL) (6 - 25)

SQL Joins comparison:

In Simple Words:

  • INNER JOIN: Returns rows only when keys match in both tables.
  • LEFT JOIN: Returns all left rows plus matched right rows (NULL if no match).
  • CROSS JOIN: Cartesian product ($M \times N$ rows; dangerous on large tables).
sql
-- LEFT JOIN: Find all users, including those who have never placed an order:
SELECT u.id, u.name, o.id AS order_id
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.id IS NULL; -- Users with zero orders