开发者

What's the different between these 2 mysql queries? one using left join

开发者 https://www.devze.com 2022-12-28 09:09 出处:网络
I see people using LEFT JOIN in their mysql queries to fetch data from two tables. But I normally do it without left joi开发者_运维技巧n. Is there any differences besides the syntax, e.g. performance?

I see people using LEFT JOIN in their mysql queries to fetch data from two tables. But I normally do it without left joi开发者_运维技巧n. Is there any differences besides the syntax, e.g. performance?

Here's my normal query style:

SELECT * FROM table1 as tbl1, table2 as tbl2 WHERE tbl1.id=tbl2.table_id

as compared to

SELECT * FROM table1 as tbl1 LEFT JOIN table2 as tbl2 on tbl1.id=tbl2.id

Personally I prefer the first style...hmm..


On a left join, all values from table1 are selected even if table2 does not contain the same id.

Your normal query style can be compared to an "inner join".

0

精彩评论

暂无评论...
验证码 换一张
取 消