cberube09 Posted April 6, 2009 Share Posted April 6, 2009 Hi, I am trying to select recently commented articles out of a database. I want to display the last 5 commented articles, so I originally just set a LIMIT to the mysql query to 5. However, if the title of the article is the same as one already being shown in the newest 5, I do not want it to show up again. To clarify, I want the 5 most recently commented UNIQUE articles to show up. So if Jim and Sue both commented on an article called Dogs, than that article would show up once in the top 5 list, and 4 other articles would show up as well. How can I do this? Link to comment https://forums.phpfreaks.com/topic/152884-limit-with-conditions/ Share on other sites More sharing options...
wildteen88 Posted April 6, 2009 Share Posted April 6, 2009 You could run a SELECT DISTINCT query. Link to comment https://forums.phpfreaks.com/topic/152884-limit-with-conditions/#findComment-802905 Share on other sites More sharing options...
cberube09 Posted April 6, 2009 Author Share Posted April 6, 2009 Thanks, that helps a lot. Didn't know that existed, I was trying to do it with some sort of PHP script. Now, I can get the latest articles that were commented on by using this code $query='SELECT DISTINCT title FROM comments ORDER BY commentid DESC LIMIT 0,5'; However, I also want to select the category that each article is in, and this category is NOT distinct. It doesn't seem like I can blend the two into one statement, so how to I find the correct category that matches up to each of the articles? Link to comment https://forums.phpfreaks.com/topic/152884-limit-with-conditions/#findComment-802922 Share on other sites More sharing options...
cberube09 Posted April 7, 2009 Author Share Posted April 7, 2009 Never mind, I finally got it. Thanks for the tip. Link to comment https://forums.phpfreaks.com/topic/152884-limit-with-conditions/#findComment-803081 Share on other sites More sharing options...
fenway Posted April 7, 2009 Share Posted April 7, 2009 Never mind, I finally got it. Thanks for the tip. Then share. Link to comment https://forums.phpfreaks.com/topic/152884-limit-with-conditions/#findComment-803958 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.