Beginner

624. JOIN Cardinality

Understand how the number of matching rows between tables affects JOIN results.

📘 Lesson 624 of 728 ⏱ 15 min 🎯 Advanced

JOIN cardinality describes the relationship and expected number of matches between rows of joined tables, such as one-to-one, one-to-many, or many-to-many.

Incorrect assumptions about cardinality can cause unexpected row multiplication and incorrect aggregates.

One customer can have many orders, creating a one-to-many relationship.

SQL
SELECT
    c.CustomerName,
    COUNT(o.OrderID) AS OrderCount
FROM Customers c
LEFT JOIN Orders o
    ON c.CustomerID = o.CustomerID
GROUP BY
    c.CustomerName;

Used in database design, query debugging, reporting, and performance optimization.

  • Cardinality describes matching relationships.
  • Common types include one-to-one and one-to-many.
  • Many-to-many relationships can multiply rows significantly.
  • Cardinality affects aggregation results.
  • Understanding relationships helps prevent JOIN errors.
What is JOIN cardinality?

It describes how many rows from one table can relate to rows in another table.

Why is cardinality important?

It helps predict result size and identify possible duplicate or multiplied rows.

Have you finished this lesson?

Introduction to SQL – All Lessons