✏️ Explanatory Question

What is the difference between an EQUI JOIN and a NON-EQUI JOIN?

👁 7 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

42

What is the difference between an EQUI JOIN and a NON-EQUI JOIN?

Level: Intermediate to Advanced — Tests your understanding of the operators used in join conditions.

The difference comes down to the operator used in the join condition:

  • EQUI JOIN: Joins tables using the equality operator (=). This is the most common join — matching a foreign key to a primary key.
  • NON-EQUI JOIN: Joins tables using any operator other than = — such as <, >, <=, >=, !=, or BETWEEN.
Key point: Almost every join you write daily is an EQUI JOIN. A NON-EQUI JOIN is used for range-based matching, like finding which salary grade an employee falls into.

Side-by-Side Comparison

Feature EQUI JOIN NON-EQUI JOIN
Operator used Only = <, >, <=, >=, !=, BETWEEN
Purpose Match exact related values Match values in a range
Frequency Very common Rare / specialized
Typical use PK–FK relationships Grades, tiers, ranges

Classic NON-EQUI JOIN Scenario

Assign each employee a salary grade from a salary_grades table that defines ranges (low–high) — a perfect case for a range-based (non-equi) join:

grade low_salary high_salary
A70000100000
B4000069999
C1000039999

Quick Example

-- EQUI JOIN: match employee's dept to a department (uses =)
SELECT e.name, d.dept_name
FROM employees e
JOIN departments d ON e.dept_id = d.dept_id;

-- NON-EQUI JOIN: place each employee into a salary grade (uses BETWEEN)
SELECT e.name, e.salary, g.grade
FROM employees e
JOIN salary_grades g
    ON e.salary BETWEEN g.low_salary AND g.high_salary;

-- NON-EQUI JOIN with > : find all employees earning more than a benchmark
SELECT a.name, b.name AS earns_less
FROM employees a
JOIN employees b ON a.salary > b.salary;
Interviewer tip: The one-liner they want — "An EQUI JOIN uses the equality operator (=) to match rows, while a NON-EQUI JOIN uses other operators like <, >, or BETWEEN for range-based matching such as salary grades."