2

我有这个查询:

SELECT `manufacturers`.*, `languages`.*, COUNT(`products`.`id`) AS productcount
FROM (`manufacturers`)
WHERE `manufacturers`.`flushed` = `0`
JOIN `languages` ON `manufacturers`.`lang` = `languages`.`id`
LEFT OUTER JOIN `products` ON 
`products`.`manuf` =  `manufacturers`.`mid`
GROUP BY manufacturers.id
ORDER BY `languages`.`id` asc, `manufacturers`.`mid` asc;

如果没有 WHERE 行,一切正常,但有了它,我的脸上就会出现错误 1064(语法错误)。我想这与查询中 WHERE 行的实际位置有关,所以我试图移动它,但没有任何运气。

我能做些什么?

4

2 回答 2

10

where 连接之后,group by 之前(连接被认为是from子句的一部分)

于 2010-06-07T12:32:15.753 回答
1

检查这个:

SELECT `manufacturers`.*, `languages`.*, COUNT(`products`.`id`) AS productcount
FROM (`manufacturers`)
JOIN `languages` ON `manufacturers`.`lang` = `languages`.`id`
LEFT OUTER JOIN `products` ON 
`products`.`manuf` =  `manufacturers`.`mid`
WHERE `manufacturers`.`flushed` = `0             -- where comes after joins 
GROUP BY manufacturers.id
ORDER BY `languages`.`id` asc, `manufacturers`.`mid` asc;
于 2010-06-07T12:35:29.653 回答