mySQL DB. Its a download log table. A user can download the same file more than once.
I want to select the last 15 unique file downloads by a given user.
So if a users last X downloads are:
UserA, file001, 14.52
UserA, file006, 14.49
UserA, file001, 14.43-Duplicate
I want to select the last x downloads but where the filename is unique, so:
UserA, file001, 14.52
UserA, file006, 14.49
I have the code to select the last 15 downloads, but i don’t know how to apply a group by/distinct to JUST the fileName column:
SELECT `fileName`,`time` FROM `downloads`
WHERE `userName` = 'userA'
ORDER BY `time` DESC
LIMIT 15
So how do i make sure only unique filenames are returned?
A
GROUP BYonfileNamewithMAXon time (to get the last time, to get the first time useMIN) should suffice.