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 |
|
leo1210
Starting Member
1 Post |
Posted - 2009-07-16 : 13:04:04
|
| hey everyone...plz reply as soon as possiblehow can i retrieve or update the last three records from a table, which doesn't hav any primary key or row numbering and without using any stored proceedures...? (is there anything like 'top' keyword?)qwerty |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-16 : 13:07:44
|
there's no concept of top or bottom in a sql table. you need to specify last or first based on order by means of order by clause. however, if you just want to update 3 random rows then use like belowUPDATE TOP (3) tSET....FROM Table1 t....WHERE ... please note this works only from sql 2005 onwards |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-16 : 13:09:17
|
if using sql 2000, you can achieve the same as follows:-SET ROWCOUNT 3UPDATE tSET....FROM Table1 t....WHERE .. |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-07-16 : 13:09:37
|
| How do you know which records are "the last three"? Last three alphabetically, last three inserted? etc.Jim |
 |
|
|
|
|
|