I have a table that contains the following fields
The database will have many records that have the same filename, userid and url values. I need to output records (Order by timeaccessed DESC) displaying "filename" (with no repeats) and the "url" for records associated with userid # 303. The most recent records (by timeaccessed) need to display first.
SELECT DISTINCT filename, url
WHERE userid = 303
GROUP BY filename
ORDER BY timeaccessed DESC ;
The problem with the output here is that it doesn't display the most recent.
In other words it selected the distinct filenames in ASC order and then displayed those in DESC order.
id filename userid url timeaccessed
1 Test1 303 test1.htm 2013-5-12 08:10:45
2 Test2 303 test2.htm 2013-5-12 08:12:28
3 Test1 303 test1a.htm 2013-5-12 08:15:32
4 Test3 303 test3.htm 2013-5-12 08:20:11
5 Test2 303 test2a.htm 2013-5-12 08:32:06
6 Test1 303 test1b.htm 2013-5-12 08:41:56
The query would return
When I need it to return