I have 2 entities, say entity [x] and [y]. both entities are associated with some tags. entity [y] is used to search for similar [x] entities. For ex. if entity [y] consist of tags “books” and “blogs”, I want a list of all the [x] entities having both of those tags.
My table schema is:
[x]
entity_id int // its a foreign key from entity table
tag varchar // this is the tag to be matched
(one entity can have multiple tags hence multiple rows of same entity
id will be inserted)
[y]
entity_id int // again a foreign key from entity2 table
tag varchar // tags again
(same comment comes here too)
One more example, say I have a [y] entity_id 10, and this 10 entity_id is associated with 3 tags, say “bus”, “train” and “plane”, when I want to look up using this entity_id 10, I want a list of [x] entity_ids associated with all these 3 tags. [x] entity_id can also have additional tags too.
Given a
y.entity_idas a parameter,10in this example, this query returns everyxrecord that doesn’t have an instance where there is ayrecord that doesn’t have a correspondingxrecord: