MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 7th, 2007, 01:39 PM
Dabizi Dabizi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 1 Dabizi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!!

Reply With Quote
  #2  
Old October 25th, 2007, 02:35 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
I'd add a field to the article and name it last_comment_date. That way you can query off of a single table.
__________________
-- Jason

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Select comments, but only by distinct articles


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway