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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:28:09+00:00 2026-06-13T14:28:09+00:00

I didn’t even know how to come up with a good title, so I

  • 0

I didn’t even know how to come up with a good title, so I hope I can describe my problem in a right way 🙂

So I have a person table, and it has a N:N relationship with keywords via the table PersonKeywords.

Then I also have a Search table, and it also has a N:N relationship with keywords via the table SearchKeywords.

Now the person can have a relationship with keyword A and B, and the search record can have a relationship with the keywords A and C.

Now I want the person in my resultset, because it has at least one (in this ‘A’) of the keywords the search record has.

I also want the person who has ‘A’, the one with ‘C’, the one with ‘A’ and ‘C’, but not the one with only B.

So it’s a match on two lists, but I don’t know where to start to create such a statement…

  • 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-13T14:28:11+00:00Added an answer on June 13, 2026 at 2:28 pm

    So you have three people…

    declare @persons table (id int identity(1,1), name varchar(10))
    insert @persons (name) values ('Babs'),('Ken'),('Neville'),('Sue')
    

    Babs has A and B, Ken has A and C, Neville has B only and Sue has C only

    declare @personkeywords table (personid int, keyword varchar(5))
    insert @personkeywords values (1,'a'),(1,'b'),(2,'a'),(2,'c'),(3,'b'),(4,'c')
    

    The search is for A or C

    declare @searchkeywords table (searchid int, keyword varchar(5))
    insert @searchkeywords values (1,'a'),(1,'c')
    

    So…

    select distinct persons.*
    from @persons persons
         inner join @personkeywords personkeywords on persons.id = personkeywords.personid
         inner join @searchkeywords searchkeywords on personkeywords.keyword = searchkeywords.keyword
    where 
         searchkeywords.searchid = 1
    

    Gives

    1     Babs
    2     Ken
    4     Sue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I didn't know a good title for my problem, this is why I didn't
I didn't really know how to formulate the title. But this is my problem.
Didn't know how to word the title sorry. Basically I have a comments system,
Didn't really know how to title this. First time writing a gem so not
Didn't know how else to put this. Say I have a JavaScript method that
I didn't know how to title this question - I am making a request
I didn't find an answer on the net and i hope this question have
Didn't even know how to exactly phrase this question, but here is the the
I didn't really know how to phrase this question, its quite strange. I have
Didn't wanna just post, Hey, guys, can you come up with an awesome randomization

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.