开发者

Invalid use of group function in MySQL 4 (not in 5)

Any idea why query

SELECT 
  m.* 
FROM 
  products_description pd, 
  products p 
  left join manufacturers m on p.manufacturers_id = m.manufacturers_id,
  products_to_categories p2c 
WHERE 
  p.products_carrot = '0' and 
  p.products_status = '1' and 
  p.products_id = p2c.products_id and 
  pd.products_id = p2c.products_id and 
  pd.langu开发者_高级运维age_id = '4' and 
  p2c.categories_id = '42'
GROUP BY manufacturers_id 
ORDER BY COUNT(*)

might give following error:

#1111 - Invalid use of group function

at MySQL 4.0.24 and not on MySQL 5.0.51 ?


Self response. Mentioning column that I want to order by in SELECT clause and aliasing it did the trick:

SELECT 
  m.*, COUNT(*) as cnt
FROM 
  products_description pd, 
  products p 
  left outer join manufacturers m on p.manufacturers_id = m.manufacturers_id,
  products_to_categories p2c 
WHERE 
  p.products_carrot = '0' and 
  p.products_status = '1' and 
  p.products_id = p2c.products_id and 
  pd.products_id = p2c.products_id and 
  pd.language_id = '4' and 
  p2c.categories_id = '42'
GROUP BY p.manufacturers_id 
ORDER BY cnt
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜