Beginner

623. JOIN Selectivity

Understand how the uniqueness and distribution of JOIN values affect query performance.

📘 Lesson 623 of 728 ⏱ 14 min 🎯 Advanced

Selectivity describes how effectively a condition reduces the number of matching rows. Highly selective conditions usually identify fewer rows.

Understanding selectivity helps explain why some JOINs and filters perform better than others.

A JOIN using a unique CustomerID generally has different behavior from a JOIN using a common Country value.

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

Used in database optimization, index design, query tuning, and performance troubleshooting.

  • Selective conditions reduce matching rows.
  • Unique keys are generally highly selective.
  • Low-selectivity columns may match many rows.
  • Data distribution influences optimizer decisions.
  • Indexes are more useful for some selective workloads than others.
What is selectivity in SQL?

Selectivity describes how much a condition narrows the possible rows.

Why does selectivity matter for JOIN performance?

Highly selective conditions can reduce the amount of data the database needs to process.

Have you finished this lesson?

Introduction to SQL – All Lessons