
May 7th, 2007, 01:39 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 1
Time spent in forums: 23 m 4 sec
Reputation Power: 0
|
|
|
Select comments, but only by distinct articles
Hi, I have a system where there's a table with comments on the site's Article nodes. I have it currently calling the eight most recent comments and producing a list of them.
However, it would be much more usable if it instead showed the eight most recently commented on articles. That way, if one article was recently hit with a number of comments, you wouldn't see eight links to the same article. You'd just see it at the top of the list.
Here is what we have now:
SELECT c.nid AS parent, c.uid, 'comment' AS type, c.timestamp, c.cid AS id, c.subject AS title FROM `comments` c LEFT JOIN `anonymous_comments` ac ON c.cid = ac.cid WHERE c.status = 0 ORDER BY c.timestamp DESC LIMIT 8;
I thought changing it to "SELECT DISTINCT c.nid AS parent" would fix things (even though I know Distinct isn't the best way to do things) but it produces the same results. Any clues?
Also, the LEFT JOIN of `anonymous_comments` GREATLY increases the query time, and I'm not sure. Is there a better way to handle that?
Thanks!!
|