View Full Version : Best way to show 500 most recent?
wilcosky
10-16-2009, 01:25 AM
Hello,
Is this the best way to show the 500 most recent records in my database. It works, but, I want to make sure it's the fastest, most efficient way.
SELECT * FROM entries ORDER BY id DESC LIMIT 500
Thanks!
It would be better if, instead of the star selector, you call each column (by name), that you require. If you alter your database in the future and add more cols, your current query will retrieve them as well and this would introduce further inefficiencies.
Specifying the columns would also help when coding or debugging because the names will be there on the script, saving you time flipping between the script and the db. And also, if you were to develop a habit of using the star selector, you may well run into ambiguity problems when you need to join tables.
hth
bazz
Old Pedant
10-16-2009, 05:29 AM
Everything Bazz said is true.
I would only like to comment that if the ID field is an autonumber field that is also your table's Primary Key, then the selection criteria couldn't be any more efficient. That will do the bare bones minimum "fetching" that it possibly can.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.