Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

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

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

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

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:14:44+00:00 2026-05-25T16:14:44+00:00

I have a product search query which returns rows similar to this: | id

  • 0

I have a product search query which returns rows similar to this:

| id | name | search tag |
| 1  |  cat |  furry     |
| 1  |  cat |  ginger    |
| 2  |  dog |  furry     |

What I need to do is be able to get the single row that matches more than one search tag – for this example, a search for furry AND ginger returns no rows because there is only one search tag per row (this is because to get these results I’m using an INNER JOIN).

My question is, what do I need to do to be able to test for furry AND ginger in the query and return the cat but not the dog?

I’m doing this in PHP.


UPDATE

In order to cope with users putting in duplicate tags, a simple fix to the HAVING condition will return rows that have duplicate tags rather than ignoring them:

mysql> select id, name, group_concat(tag) as tags, 
count(tag) as cnt from animals where tag in ('furry', 'ginger') 
group by id HAVING cnt>=2;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:14:44+00:00Added an answer on May 25, 2026 at 4:14 pm

    You could first select the rows that have the desired tags, then group them by animal ID. Count how many results you get per animal and if it’s the same as the number of tags you wanted you got a match.

    mysql> select id, name, group_concat(tag) as tags, 
    count(tag) as cnt from animals where tag in ('furry', 'ginger') 
    group by id HAVING cnt=2;       
    +----+------+--------------+-----+
    | id | name | tags         | cnt |
    +----+------+--------------+-----+
    |  1 | cat  | furry,ginger |   2 |
    +----+------+--------------+-----+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query, which performs a full-text search (CONTAINSTABLE) on the Products
Ok, so I have this search box in which people typein a food item.
I have a product search page with the form below. The search result is
I have a field 'Description' which can have product descriptions with any unicode characters.
I have a product, X, which we deliver to a client, C every month,
I have a product which has been traditionally shipped as an MSI file. It
I have a two tables as follows: product category(t1): id name product master(t2): id
I have a model Category, which has_many Products, and a Product in turn has_many
I have managed to build an index in Solr which I can search on
On the website I'm developing, I have a search box with which I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.