Sign Up

Captcha Click on image to update the captcha.

Have an account? Sign In Now

Sign In

Discover the power of expert communities in searching for solutions.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question. Please subscribe to paid membership

Forgot Password?

Don't have account, Sign Up Here
Please subscribe to paid membership

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

GetSolu.com

GetSolu.com Logo GetSolu.com Logo

GetSolu.com Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Home
  • About Us
  • Blog
  • Contact Us
Home/ Problems/Q 4039
Next
Need More Solution
Anonymous
  • 0
Anonymous
Asked: April 5, 20232023-04-05T07:40:00+00:00 2023-04-05T07:40:00+00:00In: Website Development

How to find comments with specific phrases in MySQL?

  • 0

I’m working with a MySQL database that contains comments related to orders. I want to find all the comment_post_IDs that have more than one comment with the phrase “Dintero Order created with” and also have at least one comment with the phrase “The Dintero order”. I tried using this query: select comment_post_ID,comment_content, COUNT (comment_post_ID) from wpvo_comments where comment_content like “Dintero Order created with%” AND comment_content LIKE “The Dintero order%” GROUP BY comment_post_ID HAVING COUNT (comment_post_ID)>1 ORDER BY `wpvo_comments`.`comment_post_ID` DESC; But it didn’t work as expected. It returned zero results, even though I know there are some comment_post_IDs that match my criteria. For example, here is a screenshot of one such comment_post_ID: [insert image link] How can I modify my query to get the correct results? What am I doing wrong in my current query? Any help would be appreciated. Thanks in advance.

mysql
  • 1 1 Solution
  • 20 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    1 Solution

    • Voted
    • Oldest
    • Recent
    1. Mr. Zero
      2023-04-05T07:42:34+00:00Added an answer on April 5, 2023 at 7:42 am

      The problem with your current query is that you are using the AND operator to combine two conditions that are mutually exclusive. You are asking for comments that contain both “Dintero Order created with” and “The Dintero order”, but these are two different phrases that appear in different comments. Therefore, your query will never return any results.

      What you need to do is to use a subquery to find the comment_post_IDs that have more than one comment with “Dintero Order created with”, and then join it with the original table to filter out the ones that also have at least one comment with “The Dintero order”. Here is an example of how you can do that:

      select c.comment_post_ID,c.comment_content from wpvo_comments c
      join (
      select comment_post_ID from wpvo_comments
      where comment_content like “Dintero Order created with%”
      group by comment_post_ID
      having count(comment_post_ID) > 1
      ) d on c.comment_post_ID = d.comment_post_ID
      where c.comment_content like “The Dintero order%”
      order by c.comment_post_ID desc;

      This query will first find the comment_post_IDs that have more than one comment with “Dintero Order created with” in the subquery d, and then join it with the original table c to filter out the ones that also have at least one comment with “The Dintero order”. The result will be a list of comment_post_IDs and comment_contents that match your criteria, ordered by comment_post_ID in descending order.

      I hope this helps you solve your problem. If you have any questions or feedback, please let me know.

      • 0
      • Share
        Share
        • Share onFacebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Add Your Problem

    Stats

    • Problems 31
    • Solutions 39
    • Best Solutions 5
    • Users 73
    • Popular
    • Solutions
    • Anonymous

      Create and print invoice from website used Woocommerce with WordPress

      • 2 Solutions
    • Anonymous

      Need show post by timeline on my blog website

      • 2 Solutions
    • Anonymous

      I want to find a software collage of photos with ...

      • 2 Solutions
    • Anonymous

      How to hide products that ware sold out in woocommerce?

      • 2 Solutions
    • Anonymous

      SMTP Error: Could not authenticate. Zoho mail

      • 2 Solutions
    • Mr. Zero
      Mr. Zero added an answer The future may seem uncertain and project progress could potentially… April 20, 2023 at 3:23 pm
    • Mr. Zero
      Mr. Zero added an answer One possible solution to your problem is to use the… April 5, 2023 at 8:06 am
    • Mr. Zero
      Mr. Zero added an answer One possible way to get the page URL by the… April 5, 2023 at 7:58 am
    • Mr. Zero
      Mr. Zero added an answer One possible reason why your custom font is not loading… April 5, 2023 at 7:49 am
    • Mr. Zero
      Mr. Zero added an answer The problem with your current query is that you are… April 5, 2023 at 7:42 am

    Top Members

    Pemberton Lockwood

    Pemberton Lockwood

    • 0 Problems
    • 4 Solutions
    Master
    Idris Rhiannon

    Idris Rhiannon

    • 0 Problems
    • 3 Solutions
    Master
    Kevin Hernandez

    Kevin Hernandez

    • 0 Problems
    • 2 Solutions
    Master

    Trending Tags

    affiliate marketing ai career development freelance job income generation paywall profitable website startup woocommerce wordpress

    Explore

    • Home
    • Communities
    • Questions
      • New Questions
      • Trending Questions
      • Must read Questions
      • Hot Questions
    • Polls
    • Tags
    • Badges

    Footer

    At GetSolu, we hold the belief that discovering solutions to the challenges that you may face should not be an isolated pursuit. This is why we have established a community comprised of proficient experts and knowledgeable individuals who possess a strong desire to assist you in surmounting your difficulties. All that is required of you is to provide a comprehensive description of the issue that you are experiencing, and our team of experts will furnish you with customized solutions that are tailored to your needs. Our unwavering dedication to aiding you in locating the appropriate solutions and connecting you with the necessary resources to thrive remains resolute. There is no need to hesitate. Join our community today and witness the potency of collaborative problem-solving.

    • Terms of Service
    • Privacy Policy

    Follow

    © 2023 Get Solu. All Rights Reserved
    With Love by Mr. Zero.