#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Posts
    14
    Rep Power
    0
    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?

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    81
    Rep Power
    15
    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;

Similar Threads

  1. League table problem
    By silverduck in forum MySQL Help
    Replies: 8
    Last Post: February 10th, 2004, 12:38 PM
  2. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 06:19 PM
  3. Replies: 1
    Last Post: January 20th, 2004, 01:39 PM
  4. select cell in table
    By frazzle in forum HTML Programming
    Replies: 6
    Last Post: January 20th, 2004, 09:52 AM
  5. select from table with parameter from another
    By PHPme in forum MySQL Help
    Replies: 9
    Last Post: January 14th, 2004, 08:26 PM

IMN logo majestic logo threadwatch logo seochat tools logo