mysql SELECT"FROM t1,t2"; -或者-"FROM t1 JOIN t2 ON"; [英] mysql SELECT "FROM t1, t2" -or- "FROM t1 JOIN t2 ON"
问题描述
此查询之间有什么区别?我应该选择哪一个?为什么?
what is the different between this queries? which one should I prefer and why?
SELECT
t1.*,
t2.x
FROM
t1,
t2
WHERE
t2.`id` = t1.`id`
或
SELECT
t1.*,
t2.x
FROM
t1
INNER JOIN # LEFT JOIN ?
t2
ON t2.`id` = t1.`id`
使用逗号与使用LEFT JOINS具有相同的效果吗?
Does using commas has the same effect than use LEFT JOINS?
这很尴尬.多年来,这是我第一次问自己.我曾经使用过第一个版本,但是现在感觉就像我在第一个SQL归纳中错过了几行. ;)
That's embarrassing. It's the first time I asked myself about this for years. I ever used the first version, but now i'm feeling like I missed some lines in my first SQL induction. ;)
推荐答案
逗号"语法等效于INNER JOIN语法.无论您如何查询,查询优化器都应该为您运行相同的查询.一般建议使用JOIN语言进行联接,并使用WHERE语言进行过滤,因为这样可以使您的意图更加明确
The "comma" syntax is equivalent to the INNER JOIN syntax. The query optimizer should be running the same query for you regardless of how you ask for it. There's a general recommendation to do your joins using the JOIN language and do your filtering using the WHERE language as it makes your intention more clear
这篇关于mysql SELECT"FROM t1,t2"; -或者-"FROM t1 JOIN t2 ON";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!