>I have a table with texts, all of different type, I have field named 
>type to know which is which. What I would want is with one SQL query 
>select the latest from each type, but this query...
>
>select id, headline, type from texts group by type order by date;
>
>will give the first of each type. I would like to specify "order by" 
>before "group by", but that won't work. Is there a way to list the 
>latest of each type?
>
>thanks for any answers...
>--
>Sandman[.net]

Sir, try

        SELECT d1.id, d1.headline, d1.type
        FROM your_table d1, your_table d2
        WHERE d1.id = d2.id
        GROUP BY d1.id, d1.date
        HAVING Max(d1.date) = Max(d2.date);

I went to my website at http://users.starpower.net/rjhalljr (click on 
MySQL on the side bar) and copied this. The only changes were 
plugging in your column names. There an explanation of how this 
works, but I have to admit it's not one of my better pieces of 
expository writing. I should rewrite it, but I'm unemployed and job 
hunting, working on a web page that describes how to deal with tree 
structures in MySQL, and finishing up an Excel app that creates 
regression models of programmers' salaries, so god knows when I'll 
get around to the rewrite.

Bob Hall

Know thyself? Absurd direction!
Bubbles bear no introspection.     -Khushhal Khan Khatak
MySQL list magic words: sql query database

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to