At 16:30 -0400 5/9/02, Andrew Kuebler wrote: > I want to select say 100 of 1,000 records and get the highest value for > "id" in that query, however the MAX command always gives me the MAX for > the whole table, not just my query. > > Here's my expression: > SELECT MAX(id) FROM table WHERE DATE = '20020509' LIMIT 100 > No matter what, I will always get the max for the column for the whole > table....adding and removing the "LIMIT" command changes absolutely > nothing...
As Paul wrote, LIMIT is applied after everything else. Basically, MAX() won't help you here, since it is applied *before* the LIMIT. That's the fundamental problem with the above query. How about this: SELECT id FROM table WHERE DATE = '20020509' ORDER BY id LIMIT 99,1 This applies your date condition, sorts by id in ascending order and then grabs only row 100. Regards, Arjen. -- MySQL Training in Australia: 9-13 Sep 2002, https://order.mysql.com/?marl __ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Mr. Arjen G. Lentz <[EMAIL PROTECTED]> / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Technical Writer, Trainer /_/ /_/\_, /___/\___\_\___/ Brisbane, QLD Australia <___/ www.mysql.com --------------------------------------------------------------------- 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