MySQL GROUP BY returns only the first row

I have a table with a name formswith the following structure -

GROUP       | FORM       | FILEPATH
====================================
SomeGroup   | SomeForm1  | SomePath1
SomeGroup   | SomeForm2  | SomePath2
------------------------------------

I am using the following query -

SELECT * FROM forms GROUP BY 'GROUP'

It returns only the first row -

GROUP       | FORM       | FILEPATH
====================================
SomeGroup   | SomeForm1  | SomePath1
------------------------------------

Shouldn't both (or all) be returned? Or am I (possibly) wrong?

+5
source share
9 answers

Thanks to everyone for pointing out an obvious mistake that I'm too blind to see. I finally replaced GROUP BYwith ORDER BYand included the sentence WHEREto get the desired result. This is what I was going to use all this time. I am stupid.

My last request will be as follows:

SELECT * FROM forms WHERE GROUP='SomeGroup' ORDER BY 'GROUP'
0
source

As the manual says:

SQL , GROUP BY, , GROUP BY. , SQL, name GROUP BY:

SELECT o.custid, c.name, MAX(o.payment)
  FROM orders AS o, customers AS c
  WHERE o.custid = c.custid
  GROUP BY o.custid;

, name GROUP BY.

MySQL GROUP BY, , GROUP BY. , MySQL. , . , , , GROUP BY, . , , , .

MySQL , ( , , ) .

+11

, GROUP ... GROUP BY.

Btw, GROUP BY , COUNT(), MIN(), MAX(). MySQL , ; .

+2

:

SELECT * FROM forms GROUP BY 'GROUP'

"" SQL, MySQL , group by. . , , , .

+1

mysql, .

10 . mysql- :

SELECT * FROM forms GROUP BY 'ID'; // returns only one row

:

SELECT ID FROM forms GROUP BY 'ID'; // returns only one row

:

SELECT ID FROM forms GROUP BY ID; // returns more than one row (with one column of field "ID") grouped by ID

SELECT * FROM forms GROUP BY ID; // returns more than one row (with columns of all fields) grouped by ID

SELECT * FROM forms GROUP BY `ID`; // returns more than one row (with columns of all fields) grouped by ID

: Donot , , stringty . , . escape-, . ID

+1

; .

0
SELECT * FROM forms GROUP BY `GROUP` 

,

0

, .

, GROUP BY, ( MySQL). .

, () , GROUP BY. GROUP, "SomeGroup", .

0

Group bycondition should be necessary only if you have any function groups such as max, min, avg, sumetc., used in the query expressions. There are no such features in your request. This means that you really do not need an offer Group by. And if you are still using such an offer, you will only get the first record from the grouped results.

Therefore, the conclusion on your request is excellent.

0
source

All Articles