If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
Table like this:
date | id | value
2003-10-01 | A | 100
2003-10-02 | A | 300
2003-10-03 | A | 200
2003-10-01 | B | 300
2003-10-02 | B | 100
2003-10-02 | C | 200
Should return result like this:
date | id | value
2003-10-03 | A | 200
2003-10-02 | B | 100
2003-10-02 | C | 200
Point is to select the newest record (by date) for each of the id (only one for each id)
SELECT DISTINCT... will return all records.
SELECT ... ORDER BY date DESC LIMIT 1 will return just 1 record.
SELECT MAX(date), id, value FROM table GROUP BY id
will return unpredictable (some times correct) result.