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
https://forums.phpfreaks.com/topic/59549-solved-adding-some-conditions-to-a-query/
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

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.