★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum4/HTML/000841.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  MySQL
  SELECT max(id) FROM table WHERE id<$id

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   SELECT max(id) FROM table WHERE id<$id
Martijn
Junior Member
posted August 14, 2000 06:34 AM     Click Here to See the Profile for Martijn   Click Here to Email Martijn     Edit/Delete Message Reply w/Quote
SELECT max(id) FROM table WHERE id<$id

When there is no max(id) it still returns an empty value...why?, and how do i solve this?

christucker2
Member
posted August 14, 2000 07:25 AM     Click Here to See the Profile for christucker2     Edit/Delete Message Reply w/Quote
I'm afraid you're going to have to give a little more detail on this one. What do you mean by "When there is no max(id) it still returns an empty value"? How is there no max id, and what is the empty value it returns? Does it just return no rows, or does it return zero, or what?

You may be able to fix the problem by being more explicit about the use of the max function, though without further details I can't be sure. max is an aggregate function and so expects an aggregate group to operate on. Therefore, you should always specify a group by clause on your select -- in this case, MySQL may automagically put one there, but it's better to be explicit. So, change your query to:
select max(id) from table where id < $id group by id;

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.