MySQL Forums
Forum List  »  InnoDB

Re: Group by
Posted by: Roland Bouman
Date: January 06, 2006 01:55PM

Hi,


[this has got nothing to do with transactions - post stuff like this to the general forum next time]

Well, there is something strange here. You GROUP BY only col2, but you SELECT *; that is, you SELECT id, col1 and col2. As a general principle, you should GROUP BY all the expressions that define a group. For each group that you select in this way, you can SELECT an aggregate: COUNT, SUM, AVG etc (see http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html). It is an error to have those expressions in your GROUP BY list.

So first, you have to have a clear idea what defines a group. Is it col1? Your query seems to imply that, because you have a WHERE col1 = 'someval' clause. However, your resultset contains two distinct values for col1, a1 and a2, so what's the deal here? Is that your total data set?

Please post exactly what you want your query result to be for a particular query for a particular dataset. Thank you.

Roland

Options: ReplyQuote


Subject
Views
Written By
Posted
3279
January 06, 2006 06:34AM
Re: Group by
1782
January 06, 2006 01:55PM
1724
January 07, 2006 01:06AM
1744
January 07, 2006 02:49AM
1862
January 08, 2006 07:42AM
1856
January 08, 2006 07:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.