mysql first record retrieval

Posted by Sammy on Stack Overflow See other posts from Stack Overflow or by Sammy
Published on 2010-05-23T04:58:12Z Indexed on 2010/05/23 5:00 UTC
Read the original article Hit count: 477

Filed under:
|
|

While very easy to do in Perl or PHP, I cannot figure how to use mysql only to extract the first unique occurence of a record.

For example, given the following table:

Name Date Time Sale John 2010-09-12 10:22:22 500 Bill 2010-08-12 09:22:37 2000 John 2010-09-13 10:22:22 500 Sue 2010-09-01 09:07:21 1000 Bill 2010-07-25 11:23:23 2000 Sue 2010-06-24 13:23:45 1000

I would like to extract the first record for each individual in asc time order. After sorting the table is ascending time order, I need to extract the first unique record by name.

So the output would be :

Name Date Time Sale John 2010-09-12 10:22:22 500 Bill 2010-07-25 11:23:23 2000 Sue 2010-06-24 13:23:45 1000

Is this doable in an easy fashion with mySQL?

Thanks, Sammy

© Stack Overflow or respective owner

Related posts about distinct

Related posts about last