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 |
|
asifbhura
Posting Yak Master
165 Posts |
Posted - 2006-06-19 : 02:59:51
|
| Dear,I have written query to select top3 records, as belowselect top 3 c_name,c_add from customersit is working ok.but when i insert new records even though it doesnt fetch new inserted records, I want top 3 records which are inserted last.is there any query like?select last 3 c_name,c_add from customeri want only 3 records which are inserted last.Please help meregards, |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-06-19 : 03:02:42
|
if you have a datetime field you can use top or an incremental ID perhapsotherwise, AFAIK the only way is via trigger --------------------keeping it simple... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-06-19 : 03:12:09
|
Have a datetime column in your table to record the record creation date.then use TOP 3 with ORDER BY ... DESC KH |
 |
|
|
sqldev80
Yak Posting Veteran
68 Posts |
Posted - 2006-06-19 : 13:14:57
|
| alter table tablenameADD DATE datetime NULLCONSTRAINT DATE_tablenameDEFAULT CONVERT(VARCHAR(10), GETDATE(), 126) with valuesGOselect top 3 from tablename order by DATE DESC |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2006-06-19 : 21:28:45
|
| You should use an identity because there is no guarantee that the date time will be unique. An identity will always give you a new value for each row. |
 |
|
|
|
|
|