On Monday 17 January 2011 09:53, Steve Meyers wrote:
> 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).

moving the "group by" to after "order by" will result in an error:

mysql> select album_id, updated_at, created_at from album_stats order by 
updated_at group by album_id desc limit 8;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual 
that corresponds to your MySQL server version for the right syntax to use 
near 'group by album_id desc limit 8' at line 1

Beside, since I'm using Propel and Creole for ORM and database abstraction, I 
would never be able to change the order of them.

-- 
Jørn Dahl-Stamnes
homepage: http://www.dahl-stamnes.net/dahls/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to