- LEFT [OUTER] JOIN 包含左边表的全部行,如果与右表中的数据列没有匹配,则添加为空值 NULL 数据
语法
table_reference
LEFT [OUTER] JOIN table_reference
ON search_condition
| USING (column_name [, column_name] ...)
[WHERE where_condition];
参数 |
说明 |
||||||
table_reference{ table_factor | joined_table } |
|
||||||
search_condition |
条件语句 |
||||||
column_name |
数据列名 |
||||||
tbl_name |
数据表名 |
||||||
[WHERE where_condition] |
WHERE条件语句 |
示例
SELECT Person.name,Order.orderNo
FROM Person
LEFT JOIN Order
ON Person.id=Order.id
运行结果如下:
name |
orderNo |
Adams |
22456 |
Adams |
24562 |
Carter |
77895 |
Carter |
44678 |
PETER |
NULL |
示例
SELECT Person.name,Order.orderNo
FROM Person
LEFT JOIN Order
ON Person.id=Order.id
WHERE Person.name LIKE 'P%'
运行结果如下:
name |
orderNo |
PETER |
NULL |