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 7501565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:34:46+00:00 2026-05-29T20:34:46+00:00

I need to store a group of tags applied to objects. I was thinking

  • 0

I need to store a group of “tags” applied to objects. I was thinking of using something along the lines of :
enter image description here

But in order to implement gmail’s “Implicit Social Graph” algorithm (see this question), I need to be able to search for groups of tags that contain one or more specific tags.

So I guess my question is how to get the intersection of two groups of items, in mysql, in the most efficient way ?

  • 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-29T20:34:49+00:00Added an answer on May 29, 2026 at 8:34 pm

    find all sets containing one specific tag (given the value):

    select tags_sets_id
    from tags_has_sets, tags
    where value = 'foo'
    and tags_id = id;
    

    find all sets containing either of two (or more) specific tags (given the values):

    select distinct tags_sets_id 
    from tags_has_sets, tags 
    where value in ('foo', 'bar') 
    and tags_id = id;
    

    find all sets containing both of exactly two specific tags:

    select t1.tags_sets_id 
    from tags_has_sets t1, tags tags1, 
      tags_has_sets t2, tags tags2 
    where tags1.value = 'foo' 
    and tags2.value = 'bar' 
    and t1.tags_id = tags1.id 
    and t2.tags_id = tags2.id 
    and t1.tags_sets_id = t2.tags_sets_id;
    

    note that the last solution doesn’t generalize, but you could conceivably build a generalized algorithm to generate an n-joined sql statement on the fly.

    here is one last implementation that does generalize, although i don’t know its performance characteristics compared to the generated-join way (thanks to @ypercube for an excellent enhancement to my initial suggestion):

    select tags_sets_id
    from tags_has_sets, tags
    where value in ('foo', 'bar', 'baz')
    and id = tags_id
    group by tags_sets_id
    having count(*) = 3;
    -- formerly: having group_concat(distinct value order by value)
    --   ='bar,baz,foo';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using postgresql and python and I need to store data group by week
I need to store app specific configuration in rails. But it has to be:
I need to store user entered changes to a particular table, but not show
I've got a whole bunch of elements that I need to group, but because
APC lets you store data inside keys, but you cannot group these keys. So
I need to extract the text between two HTML tags and store it in
I need to store an unknown number of groups. Each group has an unknown
I need to implement following categorization in SQL: group can contain multiple tests or
I have id values for products that I need store. Right now they are
I need to store around 100 millions of records on the database. Around 60-70%

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.