Updated on 2026-11-06 GMT+08:00

NON-EQUI JOIN

Function

In a NON-EQUI JOIN, multiple tables are joined using NON-EQUAL JOIN values, and the result set satisfying the inequality condition is returned.

Syntax

SELECT attr_expr_list FROM table_reference
  JOIN table_reference ON non_equi_join_condition;

Parameters

Parameter

Description

attr_expr_list

The list of query column expressions, specifying the columns to be returned.

table_reference

The table name or subquery to be joined. Must be an existing table. Otherwise, an error is reported.

JOIN

The JOIN keyword. Can be INNER JOIN, LEFT OUTER JOIN, etc.

non_equi_join_condition

The non-equi join condition. Uses inequality operators (such as <>, <, >, <=, >=) instead of the equals sign for joining.

Precautions

  • The tables to be joined must already exist. Otherwise, an error is reported.
  • The join conditions for NON-EQUI JOINS are all inequality conditions, which is different from EQUI-JOINS (which use = for comparison).
  • NON-EQUI JOINS may result in a large result set. Use with caution.

Examples

Return all combinations of student name pairs from the student_info_1 and student_info_2 tables, excluding name pairs with the same name.

SELECT student_info_1.name, student_info_2.name FROM student_info_1 JOIN student_info_2 ON student_info_1.name <> student_info_2.name;

Example of a NON-EQUI JOIN using a range condition:

SELECT a.name, b.name FROM student_info_1 a JOIN student_info_2 b ON a.score > b.score;