Mysql max data wg id
Mamy następującą tabelę z danymi:
ID | Forename | Surname | Created ------------------------------------ 1 | Tom | Smith | 2008-01-01 1 | Tom | Windsor | 2008-02-01 2 | Anne | Thorn | 2008-01-05 2 | Anne | Baker | 2008-03-01 3 | Bill | Sykes | 2008-01-20Chcemy otrzymać:
ID | Forename | Surname | Created ------------------------------------ 1 | Tom | Windsor | 2008-02-01 2 | Anne | Baker | 2008-03-01 3 | Bill | Sykes | 2008-01-20Wykorzystamy podzapytanie, kod sql poniżej
SELECT ID, Forename, Surname FROM Name AS t WHERE Created = ( SELECT MAX(Created) FROM Name WHERE ID = t.ID )