At 03:08 PM 8/3/2006, André Hänsel wrote:
Hi,
I have a table logging downloads (time, username, download).
Now I'd like to have the last 5 downloads per user.
Can someone tell me a solution (or what to search for)?
Regards,
André
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
Correlated subquery, which can be the devil to debug, and don't run really
quickly.
I have no idea if this will work:
SELECT t1.time, t1.username, t1.download FROM downloads AS t1
WHERE t1.username = ANY
(SELECT t2.username FROM downloads AS t2 WHERE t2.username =
t1.username)
ORDER BY t1.time DESC
LIMIT 5
Hmmm, that's just going to return 5 records; you need 5 or fewer for each
username.
That's almost like creating a view of users, then stepping through the
view, selecting * limit 5 where username = view.username. See where that's
headed? You may need a temporary table.
Sorry I've not been more help.
Regards - Miles Thompson
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.1.394 / Virus Database: 268.10.5/406 - Release Date: 8/2/2006
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]