9 Years
Discussion Span
Last Post by tesuji

Hello guptaalok12,

When Edgar Frank Codd invited relational databases his primary idea was to found it on logic algebra and set theory. The Rows of relational tables (aka relations) are sets. Therefore, there aren't duplicate rows nor any particular order of rows. From this point of view, asking "How To get the 5th row from a table?" is irrelevant. Yet, to put any meaningful signification on it, your table must already have a column which allow such an ordering, for example: Birthday in a person's record. Now it would be possible ordering all persons' records by birthday to find: "Who is the fifth oldest person?". If you don't have such a special column (or set of columns) within a table, it is impossible to determine the 5th row because the 5th row you get today will be the 8th row tomorrow (e.g. due to inserting and deleting rows in the meantime).

On sql server (>2000) you can get the 5th row from our person's birthday example by two nested top clauses:

SELECT TOP 1 name, birthday 
(   SELECT TOP 5 name, birthday FROM persons 
    ORDER BY birthday ASC
) suse
ORDER BY birthday DESC


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.