August 14th, 2000, 08:34 AM
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?
August 14th, 2000, 09:25 AM
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;