[thelist] SQL Query : using Group By and Order By together

rudy r937 at interlog.com
Fri Jan 4 19:31:27 CST 2002

>    SELECT aplien, aplogo, apnom, aptime
>         FROM table
>        GROUP BY aplogo
>     ORDER BY aptime DESC
> So I concluded that the problem may come from:
> 1. the index of the mysql database, is determining the order of the logo
> not my supposed chronological order via "ORDER BY aptime DESC"
> 2. a misunderstanding of the functionning of GROUP BY

bonjour alliax

i am afraid it is #2

what GROUP BY does is create one row for each value of the group

your syntax there is faulty, because the GROUP BY column does not match the
SELECT columns

> In a 'gallery' page my goal is to list all submitted logos, by
> chronological order, but grouping them by the logo's url since people can
> submit several time the same logo..

you do not want GROUP BY, you want

      SELECT aplien, aplogo, apnom, aptime
           FROM table
       ORDER BY aplogo, aptime DESC

if you want to space the groups in your output, you need to do that in php


More information about the thelist mailing list