Jump to content

[SOLVED] Adding some conditions to a query


gausie

Recommended Posts

SELECT mak.id,mak.name,mak.rating,mak.votes,mak.user,COUNT(comments.comment) AS num_comments FROM mak LEFT JOIN comments ON mak.id=comments.about GROUP BY mak.id ORDER BY num_comments DESC LIMIT 0,10

 

That query is selecting articles (in the table 'mak') based on how many comments (in the table 'comments') they have. However, I haven now implemented service comments and would like to discout them from the counting. Any service message is like this "<i>%</i>%" and since there is no other way of putting <i> into the comments field, I am sure that these are all service messages. How can I add this condition to the query I have above?

 

gausie

Link to comment
Share on other sites

Try this:

 

SELECT mak.id,mak.name,mak.rating,mak.votes,mak.user,COUNT(comments.comment) AS num_comments
FROM mak LEFT JOIN comments ON mak.id=comments.about
WHERE comments.comment NOT LIKE '<i>%</i>%'
GROUP BY mak.id
ORDER BY num_comments DESC
LIMIT 0,10

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.