[thelist] sql: least/min value

Winfried Huslik winfried at huslik.de
Sun Feb 25 18:29:35 CST 2001


Nothing to be shy about! (It's obvious.) I do it the same way although 
(or because?) not being a guru.
You can even omit the ASC because it's the default.

Winfried Huslik



On 2001-02-26 0:19 Uhr, Warden, Matt (mwarden at odyssey-design.com) wrote:

>This probably isn't the best way, but here goes...
>
>> Somehow I have to select the set which has the minimum value for a
>> specific field.
>>
>> I'm doing this at the moment:
>>
>> SELECT id, file, url FROM ads WHERE state='1' AND XXXX ORDER BY id
>>
>> and for XXXX, I have tried something like least(views) or min(views) but
>> neither work.
>>
>> I'm using mySQL for this and I'm really confused as I think it *has* to
>> be very easy, but I can't find the appropriate function to do so.
>
>SELECT id, file, url FROM ads WHERE state='1' ORDER BY views ASC LIMIT 1
>
>This will only return the first record when ordered by views ascending. In
>other words, the record with the lowest value for views.
>
>Maybe some of the DB gurus on this list *cough* could help you out better.
>Even if they don't have much experience with MySQL. *cough*
>
>
>--
>mattwarden
>mattwarden.com
>
>
>---------------------------------------
>For unsubscribe and other options, including
>the Tip Harvester and archive of TheList go to:
>http://lists.evolt.org Workers of the Web, evolt ! 




More information about the thelist mailing list