View Full Version : Selecting the next row available

04-28-2006, 12:19 AM
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:

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?

04-28-2006, 12:32 AM
I know just a small amount of PHP at the moment, but I can give you the SQL to do that:

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.

04-28-2006, 12:36 AM
thanks sir.... that worked... =)