Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-08-15 : 07:03:42
|
| Richard Costin writes "How to select every nth record from a table using Microsoft SQL server?Version SQL 8.00.760" |
|
|
Amethystium
Aged Yak Warrior
701 Posts |
Posted - 2003-08-15 : 07:55:10
|
| Add a sequential column (1, 2, 3, 4 ....n) and (call it SEQ) to your table. Then do something like this :SELECT *FROM someTableWHERE SEQ%5 = 0This will return every 5th, 10th, 15th record etc..------------------------------------------------------------------------------I enjoy using SQL Server but I am not part of the Microsoft fanboy club! NEVER!! |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-08-15 : 08:11:13
|
quote: Originally posted by AskSQLTeamHow to select every nth record from a table using Microsoft SQL server?
Amethystium aludes to this, but there is an inherent misunderstanding that is revealed by your question.There is nothing in the relational model that says rows in tables are ordered. Re-read Codd's Information Rule: In the relational model, you can ONLY select a row based on its column values. NOTHING ELSE. There is no concept of row ordering. There is no first, no last, no thirty-fifth.So if you want the nth record, you need to clarify in your query by what order? So, if you want the 5th page the user visited in the session, you would have to find the row with that particular session pk and having the 5th earliest timestamp, more than likely.Jay White{0} |
 |
|
|
SqlStar
Posting Yak Master
121 Posts |
Posted - 2003-08-18 : 08:48:11
|
| "In the relational model, you can ONLY select a row based on its column values. NOTHING ELSE. There is no concept of row ordering."Yeah. That's correct.":-) IT Knowledge is power :-)" |
 |
|
|
|
|
|
|
|