[英]LEFT JOIN optimizations
I'm wondering if it's better to do joined query like that : 我想知道这样做像是更好的联接查询:
SELECT * FROM table1
LEFT JOIN table2 ON table1.field1=table2.id
AND table2.field2="mystring"
WHERE table2.field2="mystring"
Instead of simply doing it : 而不是简单地这样做:
SELECT * FROM table1
LEFT JOIN table2 ON table1.field1=table2.id
WHERE table2.field2="mystring"
Is the MySQL engine doing this optimizations for me or is it better to do it explicitly ? MySQL引擎是在为我做这种优化,还是显式地做得更好?
Does : 是否:
SELECT * FROM table1
JOIN table2 ON table2.field2="mystring" AND table2.id=table1.field1
has the same effect, will results be identical ? 具有相同的效果,结果是否相同?
Edit: Some more precisions, my questions are : 编辑:更多的精度,我的问题是:
i assume the 3 above queries are equivalent in term of given results. 我假设上述3个查询在给定结果方面是等效的。 Are they really (especially the third) ?
他们是真的吗(尤其是第三个)?
i'm wondering if the engine treat them equally in terms of performances (in other words do i have to worry wich one to use) ? 我想知道引擎在性能方面是否平等对待它们(换句话说,我必须担心要使用其中一个)吗?
This will still show records of table1 if table2.field2!="mystring" 如果table2.field2!=“ mystring”,仍将显示table1的记录
SELECT * FROM table1
LEFT JOIN table2 ON table1.field1=table2.id
AND table2.field2="mystring"
This will not show records of table1 if table2.field2!="mystring" 如果table2.field2!=“ mystring”,则不会显示table1的记录。
SELECT * FROM table1
LEFT JOIN table2 ON table1.field1=table2.id
WHERE table2.field2="mystring"
The output can be different. 输出可以不同。 The first query in this situation could show more results then the second.
在这种情况下,第一个查询可能显示比第二个查询更多的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.