For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > March 2005 > Select highest number









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Select highest number
Salve Håkedal

2005-03-10, 3:56 am

How do I select the highest number (or latest entry) from this column:
| nr | int(4) | | PRI | NULL | auto_increment |


Salve

David Robinson

2005-03-10, 3:56 am

"Salve Håkedal" <ikkje.spam.salve@fiolinmaker.no> wrote in message
news:d_QXd.1381$ai7.28570@news2.e.nsc.no...
> How do I select the highest number (or latest entry) from this column:
> | nr | int(4) | | PRI | NULL | auto_increment |
>
>
> Salve
>


I believe you can do this:

SELECT MAX(nr) as highest_number FROM table;

Of course, this will only return the one field (nr) with the highest value
the table contains. If you want other fields from the record to be included
in the results, do this:

SELECT field1, field2, MAX(nr) as highest_number FROM table;

I'm sure I'll be corrected if I'm wrong :)


Salve Håkedal

2005-03-10, 3:56 am

David Robinson wrote:

> "Salve Håkedal" <ikkje.spam.salve@fiolinmaker.no> wrote in message
> news:d_QXd.1381$ai7.28570@news2.e.nsc.no...
>
> I believe you can do this:
>
> SELECT MAX(nr) as highest_number FROM table;
>
> Of course, this will only return the one field (nr) with the highest value
> the table contains. If you want other fields from the record to be
> included in the results, do this:
>
> SELECT field1, field2, MAX(nr) as highest_number FROM table;
>
> I'm sure I'll be corrected if I'm wrong :)


That worked fine. Thank you David!

Salve
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com