Beginner

481. JOIN Duplicate Records

Understand why JOINs can create duplicate-looking records and how to identify the cause.

📘 Lesson 481 of 728 ⏱ 12 min 🎯 Intermediate

A JOIN can return multiple rows for one record when the join condition matches multiple rows in the related table. This is normal behavior for one-to-many or many-to-many relationships.

Unexpected duplicate rows can produce incorrect counts, totals, and reports if the relationship between tables is not understood.

One customer may have many orders, so joining Customers with Orders returns the customer once for every matching order.

SQL
SELECT
    c.CustomerID,
    c.CustomerName,
    o.OrderID
FROM Customers c
INNER JOIN Orders o
    ON c.CustomerID = o.CustomerID;

Important in sales reporting, transaction analysis, customer analytics, and reconciliation.

  • JOINs can legitimately return multiple rows.
  • One-to-many relationships commonly create repeated parent values.
  • Duplicate-looking rows are not always true duplicates.
  • Check the relationship before using DISTINCT.
  • Incorrect joins can create unexpected row multiplication.
Why can JOIN return duplicate-looking rows?

Because one row in one table may match multiple rows in the other table.

Should DISTINCT always be used to remove JOIN duplicates?

No. First understand why multiple rows are being returned because DISTINCT may hide a data or join-design problem.

Have you finished this lesson?

Introduction to SQL – All Lessons