SQL LESSON 13 OF 32

INNER JOIN: connect the dots

An INNER JOIN returns matching row pairs. Connect tables through related keys using ON. Use short table aliases and qualify ambiguous columns. One-to-many joins may create multiple rows per customer.

हिन्दी में समझें

INNER JOIN मिलती पंक्तियों की जोड़ियाँ देता है। ON से संबंधित कुंजियाँ जोड़ें। छोटे नाम और कॉलम का टेबल नाम रखें। एक ग्राहक की कई पंक्तियाँ आ सकती हैं।

अभ्यास: केवल paid orders का order id और ग्राहक name, order id क्रम में।

Hinglish mein samjhein

INNER JOIN matching row pairs deta hai. ON se related keys connect karo. Aliases aur qualified columns use karo. One-to-many join se multiple rows aa sakti hain.

Practice: Paid orders ke order id aur customer name, order id sorted.

A small SQL example

SELECT o.id, c.name FROM orders AS o JOIN customers AS c ON o.customer_id = c.id ORDER BY o.id;

Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.

Try this example in the SQL playground →

Practise this idea

Show order id and customer name for paid orders only, ordered by order id.

Check answer & explanation
SELECT o.id, c.name FROM orders o JOIN customers c ON o.customer_id=c.id WHERE o.status='paid' ORDER BY o.id;

ON relates each order to its customer. WHERE then keeps paid orders, and ORDER BY o.id makes the output deterministic.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

The join condition usually belongs after…

  1. ON
  2. LIMIT
  3. AS only
Check the quiz answer

ON

An INNER JOIN returns matching row pairs. Connect tables through related keys using ON. Use short table aliases and qualify ambiguous columns. One-to-many joins may create multiple rows per customer.

References & corrections

Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.