Try something like this

SELECT price, min(abs(price-value)) as Mini from table group by price order
by Mini LIMIT 1

Patrick

-----Message d'origine-----
De : Robert Badaracco [mailto:[EMAIL PROTECTED]]
Envoyé : mercredi 24 janvier 2001 05:47
À : [EMAIL PROTECTED]
Objet : How to query and return nearest value...


Hi,

I have a range of decimal numbers (Prices) in a table column that I'd
like to
run a query against. I'd like to run a query with a value that returns
the closest
price to that value if it can't find a match. Is there some function
that I can use
in my query that will allow me to do this?

Thanks,
Bob




---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to