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

LEFT SEMI JOIN

Function

A LEFT SEMI JOIN is used to view records in the left table that satisfy the JOIN condition. A LEFT SEMI JOIN only returns records from the left table and does not return columns from the right table.

Syntax

SELECT attr_expr_list FROM table_reference
  LEFT SEMI JOIN table_reference ON join_condition;

Parameters

Parameter

Description

attr_expr_list

The list of query column expressions, specifying the columns to be returned. The fields involved can only be fields from the left table. Otherwise, an error is reported.

table_reference

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

LEFT SEMI JOIN

LEFT SEMI JOIN keyword. Only displays records from the left table that satisfy the JOIN condition.

join_condition

The join condition, typically an equality comparison expression between columns of the two tables.

ON

The keyword specifying the join condition.

Precautions

  • The tables to be joined must already exist. Otherwise, an error is reported.
  • The fields involved in attr_expr_list can only be fields from the left table. Otherwise, an error is reported.
  • Difference between LEFT SEMI JOIN and LEFT OUTER JOIN: A LEFT SEMI JOIN only returns records from the left table that satisfy the JOIN condition, while a LEFT OUTER JOIN returns all records from the left table. For records that do not match the JOIN condition, the columns from the right table return NULL.
  • The effect of a LEFT SEMI JOIN is equivalent to a WHERE ... IN or WHERE EXISTS subquery.

Example

Return the names of students who have selected courses and their selected course IDs.

SELECT student_info.name, student_info.courseId FROM student_info LEFT SEMI JOIN course_info ON student_info.courseId = course_info.courseId;

Equivalent syntax (using WHERE IN):

SELECT name, courseId FROM student_info WHERE courseId IN (SELECT courseId FROM course_info);

Equivalent syntax (using WHERE EXISTS):

SELECT name, courseId FROM student_info WHERE EXISTS (SELECT 1 FROM course_info WHERE student_info.courseId = course_info.courseId);