Mysql - How do I retrieve a row with most recent update?

Discussion in 'PHP' started by phantom, Oct 15, 2007.

  1. #1
    Anyone know how I can retrieve a mysql row from a table that is the most recent update of all rows?


    I have a timestamp field on each row that updates whenever an UPDATE command is given to any row. But how do I retrieve the most recent updated row?


    Thanks in advance.
     
    phantom, Oct 15, 2007 IP
  2. Shimonenator

    Shimonenator Peon

    Messages:
    28
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi, phantom

    I think here's solution for you:

    SELECT *
    FROM your_table_name
    ORDER BY timestamp_field DESC
    LIMIT 1
     
    Shimonenator, Oct 15, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    EDIT: Beat me to it.

    
    SELECT
        MAX(timestamp) AS latest
    FROM
        table_name
    LIMIT 1
    
    Code (sql):
     
    nico_swd, Oct 15, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    ORDER BY DESC is what you are looking for.

    Peace,
     
    Barti1987, Oct 15, 2007 IP
  5. phantom

    phantom Well-Known Member

    Messages:
    1,509
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    140
    #5
    ok I got it guys .......thanks a million to all!
     
    phantom, Oct 15, 2007 IP