按ID过滤查询

时间:2016-03-25 16:13:38

标签: mysql

我尝试检索所有产品信息,按产品类别ID进行过滤。结果应该是数百种产品,但只返回5项。我的查询有什么问题?

SecondViewController

1 个答案:

答案 0 :(得分:0)

也许就像这样简单:

GROUP BY product.id_product ASC 需要是: ORDER BY product.id_product ASC

mySQL扩展了group by子句,因此不在group by中的任何列都可能获得不确定的值。

If ONLY_FULL_GROUP_BY is disabled, a MySQL extension to the standard SQL use of GROUP BY permits the select list, HAVING condition, or ORDER BY list to refer to nonaggregated columns even if the columns are not functionally dependent on GROUP BY columns. ... The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate, which is probably not what you want.

选项:

  • 按顺序更改分组
  • 通过
  • 将所有列添加到组中
  • 根本不使用group。