List:General Discussion« Previous MessageNext Message »
From:Steve Meyers Date:January 17 2011 8:53am
Subject:Re: Group by question
View as plain text  
On 1/16/11 5:22 AM, Jørn Dahl-Stamnes wrote:
> mysql>  select album_id, updated_at, created_at from album_stats group by
> album_id order by updated_at desc limit 8;

I believe that your problem is that the group by happens before the 
order by.  Since you're grouping, the updated_at column is not 
deterministic.  If there are multiple rows per album_id, any one of 
those rows could provide the updated_at column that you're then using to 
order by.  What you probably want is to select (and order by) the 
max(updated_at).

Steve
Thread
Group by questionJørn Dahl-Stamnes16 Jan
  • Re: Group by questionSteve Meyers17 Jan
    • Re: Group by questionJørn Dahl-Stamnes17 Jan
      • Re: Group by questionLuciano Furtado17 Jan
  • Re: Group by questiondan20 Jan