1

I've seen some similar types of questions on SO, however, I have not been able to find a solution to my specific issue. I want to get recent timestamp and call it in a PHP code. (FYI, these are not my real columns, just a shortened example).

my_table

row_1         row_2                  TimeStamp
======================================================
 01              04              2014-06-24 22:00:00
 02              01              2014-06-25 19:00:00   
 03              93              2014-06-27 14:00:00
 04              83              2014-06-27 14:31:20 <=== I would like to return this row (latest time)

So, what I want to do is be able to:

1) Select the "newest" row, based on timestamp AND
2) Select the 'row_2' column accordingly to the timestamp

Any help on this would be great.

Thanks in Advanced!

2 Answers2

2
  SELECT `newest`, `user_2` 
    FROM `your_table`
ORDER BY `timestamp` DESC
   LIMIT 1

The LIMIT 1 is there in order to only fetch one set of data.

padarom
  • 3,529
  • 5
  • 33
  • 57
0

I think this query is what you looking for

SELECT *
FROM my_table
WHERE TimeStamp = (SELECT max(TimeStamp) FROM my_table)

Best regards, Nebojsa

Nebojsa Susic
  • 1,220
  • 1
  • 9
  • 12