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 |
|
vs_shiva
Starting Member
5 Posts |
Posted - 2002-10-31 : 02:13:51
|
| How to display bottom of n records.eg. getting last 3 rows from the bottom. |
|
|
ashok
Yak Posting Veteran
57 Posts |
Posted - 2002-10-31 : 02:35:54
|
use TOP with a DESC clause :for e.g. using the pubs database select top 3 au_lname from authorsorder by au_lname desc will fetch the last 3 author names-ashok"Bad dancing does not brake an engagement." |
 |
|
|
vs_shiva
Starting Member
5 Posts |
Posted - 2002-10-31 : 03:07:02
|
| No ashok, desc clause is not the permanent solution. i don't want to mention any coulmn. If the column values are not in order u will have prob with desc clause.. |
 |
|
|
ashok
Yak Posting Veteran
57 Posts |
Posted - 2002-10-31 : 03:16:46
|
| There is no such thing as a record order when you do just a select i.e. when you SELECT from a table there is no rule as to how records will be ordered. Relational databases are meant to return information independent of the physical sequence of information on the hard disk.So you have to use the order by with a column.Or you can do a select all from the table and retrieve only the last 3 records from your recordset (very inefficient though...)-ashok"Bad dancing does not break an engagement." |
 |
|
|
saglamtimur
Yak Posting Veteran
91 Posts |
Posted - 2002-10-31 : 04:32:41
|
| Two possible solutions;-you can use cursors-Create a temp table with an identity col., and pass values from your table into that table, and then use top clause with order by id desc. |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-10-31 : 04:49:02
|
| I'm wondering what the purpose is for showing the bottom three records? I'm not sure that the concept of "bottom" is reliable in a relational database. If what you're really after is the latest three entries then I believe that it would be better to have a timestamp column in your table and make use of the comparative date functions. |
 |
|
|
|
|
|