本文介绍了MySQL GROUP BY只返回第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为表格的表格,结构如下 - $ / b
$ b $ pre $ GROUP | FORM | FILEPATH
====================================
SomeGroup | SomeForm1 | SomePath1
SomeGroup | SomeForm2 | SomePath2
------------------------------------

  

$ 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只返回第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:56