I've got a table that records user journals. Anyone can write a journal entry at any time.
I want to query the DB and get back the last ten active users, but I don't want duplicates. That is, if User X has written two journal entries in the last day, I want to get back a single hit for him, and nine others.
I'm trying this:
SELECT DISTINCT aid FROM `journal_table` ORDER BY jid DESC LIMIT 10
which works fine, except that I also need to get back the actual jid itself, too, so that I can link to the journal entry in question.
SELECT jid, DISTINCT (aid) FROM `journal_table` ORDER BY jid DESC LIMIT 10
That doesn't work, and I've tried various forms of it, but no luck. Any pointers?