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 |
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-05-04 : 01:22:20
|
| Dear experts, please guideHow can i find the last 5 rows in a table?thank you very muchVinod |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-04 : 01:32:09
|
| last 5 rows based on what?... do u have sample data? |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-05-04 : 01:34:23
|
| generally we will find first 5 rows by using top 1like that select * from mytable (only last five rows)how can i do that?Vinod |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-04 : 01:38:55
|
| same way top 5 but the result set in the descending order |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-05-04 : 02:23:49
|
| but the result is in reverse orderVinod |
 |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-05-04 : 02:47:30
|
select top 5 * from mytable order by mycolumn ascselect top 5 * from mytable order by mycolumn descit's up to you which you call the "first 5" and the "last 5" www.elsasoft.org |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-04 : 02:49:28
|
| Hope this will help u...if u want top 10 then put 10 instead of 5 in the below query...Select * from table where column1 >=( select top 1 column1 from table a where 5 = (Select count(distinct(column1)) from table where column1 >= a.column1)) |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2007-05-04 : 03:01:39
|
| Absolutly great pbguy................superb querythank you very muchVinod |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-04 : 04:00:38
|
| Seems you need PaginationSearch for the same here and you will find good articlesMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|