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

  • Home
  • SEARCH
  • 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 8558393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:48:05+00:00 2026-06-11T15:48:05+00:00

I am implementing a tag based searching where user can insert multiple tags to

  • 0

I am implementing a tag based searching where user can insert multiple tags to search for specific entity. One entity can have as many tags. But its not necessary to have all the tags user searched for to be listed in the results.

For example, where user enters three tags, say, “Shoes”,”leather”,”formal”, every entity having one or more of these tags can be in the list.

I am using union to return a full list of entities having any one of these keywords, but the problem is that I want them sorted according to the number of tags found in a category.

For example, entities having all three tags, “Shoes”,”leather”,”formal”, should come above then entities having only one or two of them. Is there any sql functionality to perform this kind of searching?

[EDIT]

My table layout is:

Entity table

  • Entity_name
  • Entity_id(auto inc primary key)

Tags table

  • Tag
  • Entity_id

Am unable to solve my purpose. Using this query right now:

select entity.entity_name from entity.entity_id join tags on tags.entity_id=entity.entity_id where tags.tag="first tag"
union 
select entity.entity_name from entity.entity_id join tags on tags.entity_id=entity.entity_id where tags.tag="second tag"
union 
select entity.entity_name from entity.entity_id join tags on tags.entity_id=entity.entity_id where tags.tag="third tag"

As I told, this is not solving my purpose.

  • 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-06-11T15:48:06+00:00Added an answer on June 11, 2026 at 3:48 pm

    This should do it for you:

     select entity_name, count(*) count
       from (
             select e.entity_name, t.tag
               from tag t
               join entity e on (t.entity_id = e.entity_id)
              where t.tag in ('tag', 'tag', 'tag')
             )x
      group by entity_name
      order by count desc
    

    It counts the matched tags by entity, then sorts them with the highest match first.

    Note also that boolean style fulltext matching will provide functionality like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a tree tag for one of my practice projects, where I
I'm implementing Comet using the script tag long polling technique, based on this page
I am implementing drag and drop, user can drag few images and drop them
I'm implementing a Google Suggest like autocomplete feature for tag searching using jQuery's autocomplete.
I have a jquery treeview script for implementing a tree structure with li tags..when
Given a SCHEMA for implementing tags ITEM ItemId, ItemContent TAG TagId, TagName ITEM_TAG ItemId,
I'm implementing a tagging system for a website. There are multiple tags per object
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
When implementing a hash table using a good hash function (one where the probability
When implementing the Strategy Pattern, where does one put the code that determines which

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.