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
    New Coder
    Join Date
    Apr 2006
    Location
    Planet Earth
    Posts
    59
    Thanks
    1
    Thanked 8 Times in 8 Posts

    Selecting the next row available

    I have a table where id is unique, well am trying to select the next row available but is must be less than the one already selected, lets say ID = 11 and the row before is ID = 9 so im my query i put:

    Code:
    SELECT bla bla bla FROM bla bla bla WHERE ID < ID2
    but it selects ID 1 not ID 9

    So my question: Is there i what i can select the next row with ID 9 and not return ID 1 in MySQL or work a way to do it with PHP?

  • #2
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    I know just a small amount of PHP at the moment, but I can give you the SQL to do that:

    Code:
    select [fields] from [table name] where ID = 
    	(select max(ID) from [table name] where ID < 12);
    This selects the maximum ID from all of the ID's that are less than the ID specified, using a subquery.
    My Website: DumpsterDoggy

  • #3
    New Coder
    Join Date
    Apr 2006
    Location
    Planet Earth
    Posts
    59
    Thanks
    1
    Thanked 8 Times in 8 Posts
    thanks sir.... that worked... =)


  •  

    Posting Permissions

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