Skip to content

LEFT JOIN

一句话解释

LEFT JOIN 返回每个行 从左 表; for 行使用否 match in 正确表, 正确列 是 NULL.

用大白话说

LEFT JOIN (also called LEFT OUTER JOIN) returns all rows from the left table, whether or not they have a match in the right table. When there is no match, the columns from the right table are filled with NULL.

This is useful when you want to keep all records from the left table and optionally pull in related data. For example, listing all users and their orders — users with no orders still appear, with NULL in the order columns.

LEFT JOIN is not symmetric — LEFT JOIN B is different from B LEFT JOIN . The "左" table is the one mentioned first (before the JOIN keyword).

示例

sql
-- All users, with their orders if any
SELECT users.name, orders.id AS order_id
FROM users
LEFT JOIN orders ON orders.user_id = users.id;
-- Users with no orders get NULL for order_id

每个用户 appears in result. 用户不使用顺序有 NULL for 顺序列.

相关术语

相关资源

相关课程

  • 连接

    学习不同连接类型.

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表