Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    get row with largest id num?

    i need to retrieve the first and last row of a table that has unique consecutive id numbers for each row

    i can get the first with "where num = 0"

    what about the last... keep in mind that i don't know how many entries there are.

    i'd also like this to run quickly... so retrieving all sorted descending is a last resort

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Try:
    select max(id) from table.

    Good luck;

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    what is it you are trying to do exactly? If you are trying to get that id to insert information in another row then look in the manual under last_insert_id() since you would want to use that instead in such a case.

    I'm asking because a great number of people that are not familiar with using it don't know why using max(columnname) is.

    of course if you just need to know the maximum of the column for another reason then using max(columname) is fine.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •