-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

He meant the execution order, please use the agregation function as
suggested.

On 11-01-17 05:03, Jørn Dahl-Stamnes wrote:
> 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.
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJNNHQIAAoJENgwSj9ZOOwrR9UH/RDLojUwXYB1a+fcS0kuwzFW
AZ/VdwknydB5ENkt7+MmWgHdVcPwrChE+nY2bpRI9LYp8ehUNwaeC2uV/ToWXFti
ZTnVdnFDanHy20UOF3a1X7UXW89/zTy/B06X7NP1NqmIGnAahPK6VBuIx1OP/oGZ
+es+m9BIYnuc8JzfRo5YSQuydfWIJ87ygrkodhM/C2VPBWDMwpEX/wuxgW/x+ukM
RXKaxHrHOrWc1hWLFp3P+QI+J7VNP1fh6Rxw1Q91latJkY4I3hbN9nEsXeHlD2l2
f5ZNn4LwPPNC++XpGaDqQmA0W2Sua9lHUhtVsxsJt5kIigAwNJ5GnaayY/p9apk=
=7MLg
-----END PGP SIGNATURE-----


-- 
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