Dirk
Dirk

Reputation: 6884

Multiple Groups Mysql

What does a multiple groups query actually accomplish? For example, if you have

SELECT * FROM table WHERE id = $id GROUP BY date, quantity, buyer;

What does that mean in plain English? I know what it means to "Group by date", but is "group by date, quantity" like a 2-d array?

Upvotes: 2

Views: 2910

Answers (1)

AvatarKava
AvatarKava

Reputation: 15443

It means ALL of the GROUP BY elements have to be identical in order for the records to be grouped.

For example, using:

GROUP BY start_date, category_id

Would keep rows with the same start date but different category_id as separate returned elements. Rows would need to have the same exact start_date and category_id in order to be grouped together.

Upvotes: 7

Related Questions