Jump to content

How to get last table element


aquatsr

Recommended Posts

So my SQL scripting is pretty weak, I'd appreciate some help here:I have a table, say, files, that has X number of elements in it.I want to display the information in entry X in a webpage using PHP.How do I select the last element only in an efficient manner (I can do it in a really elaborate way but I'm sure there is an easy way to do it as well)Right now I'm using something like this:

SELECT * FROM files ORDER BY file_id DESC LIMIT 0, 1

Anyone have anything better?

Link to comment
Share on other sites

While I'm on the subject, any recommendations on good SQL scripting books? I have two on PHP/MySQL application database scripting, but they focus mainly on CMS building. I'm looking for something solely focused on SQL database scripting.

Link to comment
Share on other sites

Sams Teach Yourself SQL in 24 Hours :)I like all the Sam books - they contain the right mix of explanations, examples, and exercises.About your first post, I can't think of anything more efficient, except to remove the zero from the LIMIT clause.

Link to comment
Share on other sites

Sams Teach Yourself SQL in 24 Hours :)I like all the Sam books - they contain the right mix of explanations, examples, and exercises.About your first post, I can't think of anything more efficient, except to remove the zero from the LIMIT clause.
Thanks :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...