Jump to content

LIMIT with conditions


cberube09

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.