Hi. On Fri, Feb 15, 2002 at 09:05:02PM -0800, [EMAIL PROTECTED] wrote: > In Re: Selecting records with the highest value no greater than x, ><[EMAIL PROTECTED]> wrote: > > > >Hi Brent, > > > >I cannot think of a single query doing your job.
IMO, there is one, if I did understand the question correctly: SELECT * FROM NEWS WHERE RATING <= 4 ORDER BY RATING DESC, RAND() LIMIT 1; This give back a random news entry of the highest score available, but smaller than 5. > >But it can be done with two. > > > >SELECT @maxrating := MAX(RATING) FROM NEWS WHERE RATING <= 4; > >SELECT * FROM NEWS WHERE RATING=@maxrating ORDER BY RAND() LIMIT 1; [...] > Nice, assuming that the " @maxrating " is the syntax for a local > variable within the server. Where is that discussed in the manual? They can be found under the term "user variables": http://www.mysql.com/doc/V/a/Variables.html > Some simple use of an API is the probably the best answer, it's > probably ~ 25 lines of perl. [...] Depends on the needs. A pure SQL solution should be noticeably faster. Bye, Benjamin. -- [EMAIL PROTECTED] --------------------------------------------------------------------- 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