Back to explore
CodingGemini 1.5Cached answer

Explain SQL JOINs with a clear example

A reusable AI answer archived as a public knowledge page, with model attribution, category context, and related discovery paths.

Searchable once, reusable many times. This is the core Divoly loop.

312

helpful votes

5,800

views

Answer

Generated with Gemini 1.5, contributed by Divoly library.

SQL JOINs combine rows from two tables based on a related column.

Given: **users** (id, name) and **orders** (id, user_id, product)

**INNER JOIN** — only rows that match in both tables: ```sql SELECT users.name, orders.product FROM users INNER JOIN orders ON users.id = orders.user_id; -- Returns users who have orders ```

**LEFT JOIN** — all rows from left table, matched rows from right (NULL if no match): ```sql SELECT users.name, orders.product FROM users LEFT JOIN orders ON users.id = orders.user_id; -- Returns ALL users, even those with no orders ```

**RIGHT JOIN** — opposite of LEFT JOIN. **FULL OUTER JOIN** — all rows from both tables.

Memory trick: think of Venn diagrams. INNER = intersection, LEFT = left circle + intersection.

Keep exploring

Related AI answers

View category