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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.