[thelist] sql: least/min value

Warden, Matt mwarden at odyssey-design.com
Sun Feb 25 18:19:50 CST 2001


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





More information about the thelist mailing list