以下是这两个SQL查询:
SELECT `o`.`date`, `i`.`description`, `o`.`quantity`
FROM `orders` AS `o`, `items` AS `i`
WHERE `i`.`itemID` = `o`.`itemID`;
和
SELECT `o`.`date`, `i`.`description`, `o`.`quantity`
FROM `orders` AS `o`
JOIN `items` AS `i`
ON `i`.`itemID` = `o`.`itemID`;
第一个结果减少了一个结果。 有人可以解释两者之间的区别吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
它们在功能上是等效的,因为MySQL优化器将theta连接重写为ANSI JOIN(至少MySQL 5.6)
您可以使用EXPLAIN EXTENDED your_query进行检查;显示警告;
theta style join
SELECT `o`.`date`, `i`.`description`, `o`.`quantity`
FROM `orders` AS `o`, `items` AS `i`
WHERE `i`.`itemID` = `o`.`itemID`;
ANSI JOIN
SELECT `o`.`date`, `i`.`description`, `o`.`quantity`
FROM `orders` AS `o`
JOIN `items` AS `i`
ON `i`.`itemID` = `o`.`itemID`;
唯一真正的区别在于可读性theta风格让它更容易被误认为它是一个INNER JOIN,所以养一个习惯就可以编写ANSI JOIN了