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
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
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.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.