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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:10:43+00:00 2026-05-12T13:10:43+00:00

I have a table ALPHA with 2 fields GroupId,Member: GroupId | Member; A1———-A; A1———-B;

  • 0

I have a table ALPHA with 2 fields GroupId,Member:

GroupId | Member;
A1----------A;
A1----------B; 
A1----------C;
A2----------A;
A2----------B;
A3----------A;
A3----------D;
A3----------E;

Objective: Given the input of – A,B,C – I have to query the table to find if a GroupId exists for this exact set of members. So, this is what I plan to do:

  1. Query the table for all GroupIds whose count is 3 (since my inpt is A,B,C ..I knw its 3)
  2. This will give me A1,A3. Now, query this set for exact matching Member values..which will give me A1.

I plan to write a Stored Procedure and would achieve the objective somehow. But, my question can this be achieved in a single query…a single self-join perhaps.

Clarification: The set of (A,B,C) is unique to A1. And if give an input of (A,B,C,D) the query should NOT return A1.

  • 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-12T13:10:43+00:00Added an answer on May 12, 2026 at 1:10 pm

    Answers given so far assume that the Member field is unique for any given GroupID. In work I have done this isn’t the case. And also if the group has what you’re looking for, plus some extra, you need to exlucde that group.

    SELECT
       [Alpha].GroupID
    FROM
       [Alpha]
    GROUP BY
       [Alpha].GroupID
    HAVING
           SUM(CASE WHEN [alpha].Member IN ('A','B','C') THEN 1 ELSE 0 END) = 3
       AND MIN(CASE WHEN [alpha].Member IN ('A','B','C') THEN 1 ELSE 0 END) = 1
    

    You can also replace the IN clause with a join on to a table holding the members you are searching for…

    SELECT
       [Alpha].GroupID
    FROM
       [Alpha]
    LEFT JOIN
       [Search]
           ON [Search].Member
    GROUP BY
       [Alpha].GroupID
    HAVING
           SUM(CASE WHEN [alpha].Member = [search].Member THEN 1 ELSE 0 END) = (SELECT COUNT(*) FROM [search])
       AND MIN(CASE WHEN [alpha].Member = [search].Member THEN 1 ELSE 0 END) = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.