Wendell Frohwein wrote:
Hi martin, thanks for the email. I'm sorting it out slowly but surely. I
was just a little over worked the night I wrote that novel of an email.
I don't know if you saw my latest email titled "Mysql Result". That's
the last step I am at. I used a select statement across multiple tables
to get all the values that I wanted. I forgot because I was so tired
that, once I had those values in there that I could sort by anything I
wanted to.

If you have a solution for my Mysql Result problem, that would help me
out alot. Most people are saying that I have to do a sub query, so I am
not really sure. Thanks though.

-Wendell Frohwein
[snipped from another email]
> I wanted to know if it would be possible for it to output it like so:
> +----------+-----------+-------------+----------------------+
> | makename | modelname | versionname |        years         |
> +----------+-----------+-------------+----------------------+
> | Acura    | Integra   | RS          | 92,93                |
> | Acura    | Integra   | GSR         | 94,95,96,97,98,99,01 |
> +----------+-----------+-------------+----------------------+

As penance for suggesting the quick way out in another posting, I've answered your question!

(I would've answered anyway - I'm a softie. I got distracted this morning with the whole 'work' thing - sorry for the delay.)

I remembered doing this before - and sure enough:

GROUP_CONCAT: http://dev.mysql.com/doc/mysql/en/group-by-functions.html

The relevant bits:
GROUP_CONCAT([DISTINCT] expr [,expr ...]
             [ORDER BY {unsigned_integer | col_name | expr}
                 [ASC | DESC] [,col_name ...]]
             [SEPARATOR str_val])

mysql> SELECT student_name,
    ->     GROUP_CONCAT(test_score)
    ->     FROM student
    ->     GROUP BY student_name;


mysql> SELECT student_name,
    ->     GROUP_CONCAT(DISTINCT test_score
    ->               ORDER BY test_score DESC SEPARATOR ' ')
    ->     FROM student
    ->     GROUP BY student_name;

The default separator is the comma. Just toss in a 'GROUP_CONCAT(year) AS year' and appropriate 'GROUP BY' clause and have at it.

- Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to