【发布时间】:2016-11-07 10:32:12
【问题描述】:
可能是一个愚蠢的问题,但是为什么这两个 mysql 查询给出不同的结果?
select * from table1 p join table2 m on p.mid=m.mid and m.onw=1
select * from table1 p join table2 m on p.mid=m.mid where m.onw=1
前者提供了大约 5 倍的行数。 “and m.onw=1”不是和后面查询中的“where”子句一样限制吗?
从 phpmyadmin 执行的实际实时查询是:
select * from xcart_products p join xcart_manufacturers m on p.manufacturerid=m.manufacturerid and m.onwalmart=1
(197023 total)
对
select * from xcart_products p join xcart_manufacturers m on p.manufacturerid=m.manufacturerid where m.onwalmart=1
(38996 total)
更新。似乎是 phpmyadmin 中的一个错误。如果我使用 count(*) 而不是 * 那么结果是相同的。也许 count(*) 会导致返回的行数减少?
【问题讨论】:
-
我不希望 INNER JOIN 的输出有差异,我相信 MySql 中的默认 JOIN 是 INNER JOIN。但是,LEFT JOIN 会有所不同。
标签: mysql join where-clause