My table is like this:
x
employee(empid, ename,job);
The current empid is for example 10, I want the previous and next empids from the database.
The next and previous values may not be 11 and 9 respectively, I need to get it from the database only in a single query. Could any body please help me with this?
Advertisement
Answer
ex. empid = 4
select * from employee
where empid = (select max(empid) from employee where empid < 4)
OR empid = (select min(empid) from employee where empid > 4)