开发者

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

开发者 https://www.devze.com 2022-12-27 03:15 出处:网络
Any idea why query SELECT m.* FROM products_description pd, products p left join manufacturers m on p.manufacturers_id = m.manufacturers_id,

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

精彩评论

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