PDA

View Full Version : Display 3 newest records...


Governator
01-07-2004, 11:45 PM
Hey,

How can I display the 3 newest records entered into the database?

thx

raf
01-08-2004, 12:12 AM
depends on what variables you have. If you have an auto-number columns od a datetime column (that contains the datetime when the record was created), then you can use

SELECT TOP3 var1, var2 FROM table ORDER BY var1

Bullschmidt
02-05-2004, 08:48 AM
SELECT TOP3 var1, var2 FROM table ORDER BY var1

Looks pretty good and no big deal but how about a minor finetuning (descending order) to show the most recent:

SELECT TOP 3 var1, var2 FROM table ORDER BY var1 DESC

raf
02-05-2004, 12:10 PM
Indeed
+ a small remark that TOP doesn't discriminate and you wount get a cutoff if the value for var1 is the same in row 3, row 4, row 5 etc. So you can still end up with more then three records if you doen't cerafully pick your order by variables.