RE: Outputing Distinct rows

From: Date: Mon, 11 Feb 2002 00:02:32 +0000
Subject: RE: Outputing Distinct rows
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-16775@lists.php.net to get a copy of this message
What you *should* do is have a lastUpdated field in your posts table, and the value inserted into their is the date when you update it. Then your query would be like $sql = "SELECT posts.topic_id, posts.forum_id, topics.topic_title, topics.topic_replies WHERE topics.topic_id = posts.topic_id ORDER BY posts.lastUpdated DESC LIMIT 10"; Also, this would allow for extra things in the future, such as a page showing all updates in a certain day, or within last 3 days, or something like that. Hope this helps. Adam -----Original Message----- From: KingZeus [mailto:kingzeus@cncrenegade.com] Sent: Sunday, February 10, 2002 1:36 PM To: php-db@lists.php.net Subject: Outputing Distinct rows I'll give you all the short version of what I need and if it is enough for you to help that would be great. I need to pull the last 10 updated topics from a table and output them. However, the posts table lists each post and then has a topic id. There is also a table of topics with topic id, title, etc. I cannot just pull the last 10 posts in the post table because those posts could all be for the same topic and I'm trying to output the last 10 updated topics (not posts). How can I do this? I can't find anything on the subject. This is what I tried as a random guess: $sql = "SELECT DISTINCT posts.topic_id, posts.forum_id, topics.topic_title, topics.topic_replies WHERE topics.topic_id = posts.topic_id DESC LIMIT 10"; Any ideas about what I need to do? I'm sure it is pretty simple..... Regards, Steve "KingZeus" Downs Co-Webmaster: http://www.cncrenegade.com

« previous php.db (#16775) next »