79194554

Date: 2024-11-16 05:15:27
Score: 4.5
Natty:
Report link

I have two queries-

Query 1-

SELECT COUNT(*) AS count FROM `comments` INNER JOIN `replies` ON `comments`.`comment_id` = `replies`.`reply_comm_id` WHERE CONCAT (`comment_message`, `reply_message`) LIKE ('%test%') AND `comments`.`comm_blog_id`=45;

Result for "query 1"-

Result for query 1

Query 2-

SELECT (SELECT COUNT(*) FROM `comments` WHERE `comment_message` LIKE '%test%' AND `comm_blog_id` = 45) + (SELECT COUNT(*) FROM `replies` WHERE `reply_message` LIKE '%test%' AND `reply_blog_id` = 45) AS total_count;

Result for "query 2"-

Result for query 2

The following are the tables-

"Comments" table-

Comment table

"Replies" table-

Replies table

Both have different results, but I think both "queries" are correct. Can anyone tell me which one I have to use for searching the data/string/tag/word/words (like- "test", or "test comment") from the two "tables"? Suppose I have a tag like test or test comment and I want to search this same tag in both the replies and comments tables of the comment_message and reply_message rows and count how many times it is coming/used.

Reasons:
  • RegEx Blacklisted phrase (2.5): Can anyone tell me
  • RegEx Blacklisted phrase (1): I want
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Shikha Singh