mysql join table - selecting the newest row

Posted by cmancre on Stack Overflow See other posts from Stack Overflow or by cmancre
Published on 2010-12-21T14:47:40Z Indexed on 2010/12/21 14:54 UTC
Read the original article Hit count: 172

Filed under:
|
|

Hi,

I have the following two MySQL tables

TABLE NAMES

NAME_ID   NAME
1         name1
2         name2
3         name3

TABLE STATUS

STATUS_ID    NAME_ID     TIMESTAMP
1            1           2010-12-20 12:00
2            2           2010-12-20 10:00
3            3           2010-12-20 10:30
4            3           2010-12-20 14:00

I would like to select all info from table NAMES and add most recent correspondent TIMESTAMP column from table STATUS

RESULT

NAME_ID NAME     TIMESTAMP
1       name1    2010-12-20 12:00
2       name2    2010-12-20 10:00
3       name3    2010-12-20 14:00

Am stuck on this one. How do I left join only on the newer timestamp?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql