Ian Hardingham <[email protected]> wrote:
> I wish to get the "next" record of a certain type, such that if we have
> row Id x, then:
> 
> Select the minimum id such that id > x (with some WHERE conditions)
> If there is no such id (ie x is the largest with the conditions) then
> the first id with those conditions is returned.

select coalesce (
    (select id from mytable where id > :x and conditions order by id limit 1),
    (select id from mytable where conditions order by id limit 1)
);

-- 
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to