select ... from the_table where id = (select min(id) from the_table where id > $last_id) #### select ... from the_table where id > $last_id order by id LIMIT 1