|
If I want to return six values from the middle of the table after passing the where clause and it should return the specified value along with the five next record. As for example: select * from employee where id='E000' then I want to return the record of E000 as well as the next five records of E001,E002,E003,E004,E005. Please help me to do this.
(comments are locked)
|
|
/check this it might help/ That may or may not return the correct records. But it's not how a database should be used. The database already contains the set that the six rows make up. Deconstructing them row by row, and reconstructing them into a table (row by row) is far from the best way to use a database.
Apr 16 '12 at 06:26 AM
Magnus Ahlkvist
(comments are locked)
|
|
Perhaps like this?
(comments are locked)
|
|
Personally, I do not like such alphanumeric incremented columns. You get more pains than gains unless handled as computed columns etc. In your case, if you would follow Magnus Ahlkvist's very good suggestion (which actually gives the core of the solution i.e. TOP and ORDER BY), then 'E10001' would always be sorted before 'E1001' which would not be correct. So it would always be dependent upon the LOGIC and constraints of your such alphanumeric computation of the column. If I assume that there is one alphabet and then multiple numeric characters, then one way of doing it could be But again, that could break anytime if the LOGIC of computation of the column is changed or not the same.
(comments are locked)
|

