Right now im having the following data:
Name Time
picture 2012-07-23 17:00:00
picture 2012-07-24 18:00:00
picture 2012-07-24 19:00:00
picture 2012-08-03 08:40:06
picture 2012-08-03 08:42:39
picture 2012-08-03 08:54:03
picture 2012-08-03 10:38:58
picture 2012-08-03 10:39:55
picture 2012-08-06 08:12:14
And the following SQL query:
SELECT DATE_FORMAT(DATE(DATE_SUB(time,INTERVAL 4 HOUR)),GET_FORMAT(DATE,'ISO'))
as time, uri, media_id, description
FROM media WHERE place_id = 1
GROUP BY time ORDER BY time DESC
Which works well and gives me the data i want. But the data from each unique date is ordered by the oldest date from each "day". I want it ordered by the newest. The Order By statement just order the whole result, not the dates for each day. If o just could take the newest date instead of the oldest when using Group By, but guess i have to work out something else than group by.
Edit: The following works. But i i want to return more columns from the subquery, how do I do that?
SELECT Distinct DATE_FORMAT( DATE( DATE_SUB(time, INTERVAL 4 HOUR ) ) ,
GET_FORMAT( DATE, 'ISO' ) ) AS date,
(SELECT type FROM media WHERE
DATE_FORMAT( DATE( DATE_SUB(time, INTERVAL 4 HOUR ) ) ,
GET_FORMAT( DATE,'ISO' ) ) = date Order by time DESC Limit 1) as name
FROM media