View Full Version : SELECT (most recent record) FROM table_name WHERE name="whatever";

06-13-2005, 11:42 AM
Right now I have a simple querly that will select all columns for any record WHERE name = "whatever "


SELECT * FROM table_name WHERE name="bob";

if bob has 5 records, all five records will display...

Is there a way to SELECT only the most recent record for bob?



[m] at
06-13-2005, 03:15 PM
I think adding "LIMIT 0, 1" to the end of your query should do it.

If you have further problems selecting the right record, you can also use ORDER BY and the ASC and DESC modifiers

06-13-2005, 03:49 PM
You can use the DISTINCT keyword and use an order by on a timestamp field.

06-14-2005, 02:54 AM
You need some way of identifying the most recent record - a timestamp or an auto-increment field, for example. If you don't have this, then it's difficult.