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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:19:01+00:00 2026-05-22T23:19:01+00:00

I am not sure even how to ask this question. I have a table

  • 0

I am not sure even how to ask this question.

I have a table of tags:

TagId  Tag
-----  -----
1      Fruit
2      Meat
3      Grain

I have a table of events:

EventId   Event
-------   -----------
1         Eating Food
2         Buying Food

What I need to do is bring back only Events that have all selected tags associated with it.

If three tags are selected then only show event that have all three.

For example:

Mapping Table

EventId   TagId
-------   -----
1         1
1         3
2         1

If I write a query like this:

select * from MapTable where where tagId in (1,3)

This will return Eating Food and Buying Food.

But what I need to do is bring back events that have both tags 1 and 3. This means that the only event in this case I would return would be Eating Food as it has both selected tags.

I was wondering if this can be done in TSQL or if I will have to use the business layer to translate it into the object to return back to the GUI.

Thanks.

  • 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-22T23:19:01+00:00Added an answer on May 22, 2026 at 11:19 pm

    There was a very similar question yesterday: Query for exact match of users in a conversation in SQL Server

    basically you can do this:

    DECLARE @NumTags INT = 2
    
    SELECT EventID
    FROM EventTag
    GROUP BY EventID
    HAVING
       Sum(CASE WHEN TagID IN (1, 3) THEN 1 ELSE 0 END) >= @NumTags
    

    so this will find all events that both the tags exist in (this allows for instances where those two tags exist along with any additional tags)

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

Sidebar

Related Questions

I'm embarrassed to even ask this question, but not sure of the syntax or
I'm not sure if this is even possible but here goes: Currently I have
Not even sure if this is feasible, but here's the use case: I have
Sorry, I'm not even sure how to ask this exactly... but I wrote a
I'm not even sure if this is possible but thought I'd ask anyway. Sorry
I'm not even sure if it's possible but say I have some XML: <source>
I'm not sure if this even exists or not, so I figured I would
Not sure how to ask a followup on SO, but this is in reference
currently, I am looking deeper into testing techniques, even though I am not sure
Not sure if this is possible or if I'm expressing correctly what I'm looking

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.