How To get the 5th row from a table.

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 
FROM 
(   SELECT TOP 5 name, birthday FROM persons 
    ORDER BY birthday ASC
) suse
ORDER BY birthday DESC

krs,
tesu

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.