List:General Discussion« Previous MessageNext Message »
From:Daniel Brown Date:March 4 2008 4:56pm
Subject:Re: Getting the last item in a "group by" query?
View as plain text  
On Tue, Mar 4, 2008 at 11:24 AM, Esbach, Brandon
<Esbachb@stripped> wrote:
> Thanks for the reply,
>
>  Sorry, should have been more specific on that :).
>  I need to access the last record by date for each serial_number in the
>  table (not just latest record)

    Okay, this is untested, so I don't know if it will work
Out-Of-The-Box[tm] or not, but it should at least lead you in the
right direction.  Plus, it's back on-list now, so that others can read
the results in the archives when they search on the web.  ;-)

    SELECT t.pass, t.id FROM theTable t WHERE t.serial_number IN
(SELECT DISTINCT serial_number,date FROM theTable ORDER BY date DESC
LIMIT 0,1);

-- 
</Dan>

Daniel P. Brown
Senior Unix Geek
<? while(1) { $me = $mind--; sleep(86400); } ?>
Thread
Getting the last item in a "group by" query?Brandon Esbach4 Mar
  • Re: Getting the last item in a "group by" query?Daniel Brown4 Mar
  • Re: Getting the last item in a "group by" query?Baron Schwartz4 Mar
Re: Getting the last item in a "group by" query?Daniel Brown4 Mar
  • RE: Getting the last item in a "group by" query?Brandon Esbach4 Mar
    • Re: Getting the last item in a "group by" query?Daniel Brown4 Mar