问题描述
我有一个名为表格
的表格,结构如下 - $ / b
$ b $ pre $ GROUP | FORM | FILEPATH
====================================
SomeGroup | SomeForm1 | SomePath1
SomeGroup | SomeForm2 | SomePath2
------------------------------------
$ c $
$ b 我使用以下查询 - SELECT * FROM forms GROUP BY'GROUP'
它只返回第一行 -
GROUP | FORM | FILEPATH
====================================
SomeGroup | SomeForm1 | SomePath1
------------------------------------
它不应该同时返回(或全部)吗?或者我(可能)是错的?
谢谢大家指出我看不见的明显错误。我最终用 ORDER BY
取代了 GROUP BY
,并包含了 WHERE
子句来获得我想要的结果。这正是我一直打算使用的。傻瓜我。
我的最终查询变成了这个 -
SELECT * FROM forms WHERE GROUP ='SomeGroup'ORDER BY'GROUP'
I have a table named forms
with the following structure-
GROUP | FORM | FILEPATH
====================================
SomeGroup | SomeForm1 | SomePath1
SomeGroup | SomeForm2 | SomePath2
------------------------------------
I use the following query-
SELECT * FROM forms GROUP BY 'GROUP'
It returns only the first row-
GROUP | FORM | FILEPATH
====================================
SomeGroup | SomeForm1 | SomePath1
------------------------------------
Shouldn't it return both (or all of it)? Or am I (possibly) wrong?
Thank you everyone for pointing out the obvious mistake I was too blind to see. I finally replaced GROUP BY
with ORDER BY
and included a WHERE
clause to get my desired result. That is what I was intending to use all along. Silly me.
My final query becomes this-
SELECT * FROM forms WHERE GROUP='SomeGroup' ORDER BY 'GROUP'
这篇关于MySQL GROUP BY只返回第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!