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

Alliax damiencola at wanadoo.fr
Fri Jan 4 20:20:51 CST 2002

Let's say date1 is anterior to date3
and of course date3 is anterior to date8
then, what I want as a result is:

aplogoB date7
aplogoA date1

following your email (I can't test it right now, but tomorrow I'll do it)

the SQL query to obtain this should be:
select aplogo, aptime, min(apdate)
      from table
       group by aplogo
       order by aptime DESC

now I think it's clear what I want, sorry not to have been clear since my
first post.


__ Alliax         ~CV : http://LingoParadise.com/cv.php
Un site pour Toulon : http://www.ToulonParadise.com
Un site pour Renaud : http://www.rfaucilhon.com
Un site pour Director : http://www.LingoParadise.com

-----Message d'origine-----

you mean, instead of

   aplogoA   date1
   aplogoA   date2
   aplogoA   date3
   aplogoB   date7
   aplogoB   date8

you want

   aplogoA   date1  date2  date3
   aplogoB   date7  date 8

that's very very hard to with sql

you need to use the query i gave you (without GROUP BY) and "flatten" the
results (that's a technical term) using php

no, it creates one row for each group and some *aggregate* information
about the group

using the example data above,

    select aplogo, count(*)
      from table
       group by aplogo


    aplogoA  3
    aplogoB  2

another example,

   select aplogo, max(apdate)
      from table
       group by aplogo


   aplogoA  date3
   aplogoB  date8

see?  one row per group

More information about the thelist mailing list