从左到右读取时,大约在整个FROM子句中首先出现的所有内容(包括其他JOIN,子查询,视图和存储过程)的结果大致为“左”。
这两个SQL语句是等效的,因为子句部分的=
运算符是对称的(如果a = b则b = a),因此无论顺序如何,结果都是相同的。ON
JOIN
常规联接仅显示JOIN的ON子句为true的行,而LEFT JOIN还可显示条件为false时“ left”中的记录(SELECT中存在的“ right”中的任何列均显示NULL)。
例如:
id | name owner_id | model
1 | Paul 1 | Ferrari
2 | Nancy 2 | Porsche
3 | Arthur NULL | Lamborghini
4 | Alfred 10 | Maserati
> select people.name, car.model from people join car on car.owner_id=people.id;
name | model
Paul | Ferrari
Nancy | Porsche
2 record(s) found
> select people.name, car.model from people left join car on
car.owner_id=people.id;
name | model
Paul | Ferrari
Nancy | Porsche
Arthur | NULL
Alfred | NULL
4 record(s) found
> select people.name, car.model from people left join car on
people.id = car.owner_id;
name | model
Paul | Ferrari
Nancy | Porsche
Arthur | NULL
Alfred | NULL
4 record(s) found