What's happening?
- Each user row is compared with each order row; a match adds a combined row to the result.
- INNER keeps only matches. LEFT also keeps users with no orders, filling the order columns with NULL.
- RIGHT keeps every order, including one whose user does not exist; FULL keeps unmatched rows from both sides.
Complexity
- Time
- O(n × m) compared row by row as shown; databases use hash or merge joins and indexes to do far less
- Space
- O(result rows)
Where you'll meet it
Orders with customer names, posts with authors, enrolments with courses — almost every screen in a business app is a JOIN.
Common mistake
Putting a filter on the right table in WHERE after a LEFT JOIN: it removes the NULL rows and quietly turns it into an INNER JOIN.
FAQ
What is the difference between INNER and LEFT JOIN?
INNER returns only rows that match on both sides; LEFT returns every row of the left table, with NULLs where nothing matched.
Why do some rows show NULL?
An outer join keeps a row that had no partner, and fills the missing side with NULL.
Does the database really compare every pair?
Not usually. With an index or a hash join it finds matches without checking every pair; the step-by-step view shows what the result means.