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

rudy r937 at interlog.com
Fri Jan 4 20:05:36 CST 2002


> I am afraid you've mistaken my goal, it is not to have several times the
> same logo, but to GROUP all entries featuring the aplogo into ONE row.

ah

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


> ps: you said: "what GROUP BY does is create one row for each
> value of the group" do you mean, as I think _group by_ behaves, it
> creates one row including all values of the group ?

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

gives

    aplogoA  3
    aplogoB  2

another example,

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

gives

   aplogoA  date3
   aplogoB  date8

see?  one row per group

rudy





More information about the thelist mailing list