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 - 2005-12-20 : 07:57:52
|
| Ravindra writes "How to retrieve n th row from a table" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-12-20 : 08:15:35
|
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspxpoint 2will explain all you need.Go with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-20 : 08:41:40
|
| This may be more efficient than other methodsSelect min(col) from (Select Top N col from yourTable order by col DESC) TMadhivananFailing to plan is Planning to fail |
 |
|
|
Frank Kalis
Constraint Violating Yak Guru
413 Posts |
Posted - 2005-12-20 : 10:05:12
|
More than one way to skin that cat.If you need it portable, you might doUSE PubsSELECT e1.hire_dateFROM employee AS e1INNER JOIN employee AS e2ON e1.hire_date <= e2.hire_dateGROUP BY e1.hire_dateHAVING COUNT(DISTINCT e2.hire_date) = 3 If it's stricly for SQL Server, here's another alternativeUSE PubsDECLARE @dt DATETIMESELECT TOP 3 @dt = hire_dateFROM employeeORDER BY hire_date DESCSELECT @dt --Frank KalisMicrosoft SQL Server MVPhttp://www.insidesql.deHeute schon gebloggt? http://www.insidesql.de/blogs |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-20 : 10:11:28
|
Well FrankFirst one is time consuming and second is similar to what I suggested and I always prefer to use that MadhivananFailing to plan is Planning to fail |
 |
|
|
Frank Kalis
Constraint Violating Yak Guru
413 Posts |
Posted - 2005-12-21 : 04:10:08
|
I know that the first one is probably the most costly. However, as it is ANSI-SQL almost any even half-smart database should understand it. That's why I wrote "if you need it portable". --Frank KalisMicrosoft SQL Server MVPhttp://www.insidesql.deHeute schon gebloggt? http://www.insidesql.de/blogs |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2005-12-21 : 11:38:33
|
| sorry, the correct answer was "There is no Nth row. Row numbers have no meaning in SQL SERVER".Help us help YOU!Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx*need more coffee*SELECT * FROM Users WHERE CLUE > 0(0 row(s) affected) |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2005-12-21 : 11:59:25
|
| My opinion is:nth row is defined when ordered by primary key.Any ideas ? |
 |
|
|
Frank Kalis
Constraint Violating Yak Guru
413 Posts |
Posted - 2005-12-21 : 15:02:03
|
quote: sorry, the correct answer was "There is no Nth row. Row numbers have no meaning in SQL SERVER".
Courtesy of Joe Celko...quote: Let's get back to the basics of an RDBMS. Rows are not records; fieldsare not columns; tables are not files. Since you are not thinking inthe right terms, you will never "get it" until you do.
...oh my.... --Frank KalisMicrosoft SQL Server MVPhttp://www.insidesql.deHeute schon gebloggt? http://www.insidesql.de/blogs |
 |
|
|
|
|
|