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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:49:20+00:00 2026-05-17T17:49:20+00:00

Currently struggling with finding a way to validate 2 tables (efficiently lots of rows

  • 0

Currently struggling with finding a way to validate 2 tables (efficiently lots of rows for Table A)

I have two tables

Table A

 ID 
 A
 B 
 C

Table matched

ID Number
A   1
A   2
A   9
B   1
B   9
C   2

I am trying to write a SQL Server query that basically checks to make sure for every value in Table A there exists a row for a variable set of values ( 1, 2,9)

The example above is incorrect because t should have for every record in A a corresponding record in Table matched for each value (1,2,9). The end goal is:

Table matched

ID Number
A   1
A   2
A   9
B   1
B   2
B   9
C   1
C   2
C   9

I know its confusing, but in general for every X in ( some set ) there should be a corresponding record in Table matched. I have obviously simplified things.

Please let me know if you all need clarification.

  • 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-17T17:49:20+00:00Added an answer on May 17, 2026 at 5:49 pm

    Use:

      SELECT a.id
        FROM TABLE_A a
        JOIN TABLE_B b ON b.id = a.id
       WHERE b.number IN (1, 2, 9)
    GROUP BY a.id
      HAVING COUNT(DISTINCT b.number) = 3
    

    The DISTINCT in the COUNT ensures that duplicates (IE: A having two records in TABLE_B with the value “2”) from being falsely considered a correct record. It can be omitted if the number column either has a unique or primary key constraint on it.

    The HAVING COUNT(...) must equal the number of values provided in the IN clause.

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

Sidebar

Related Questions

I'm struggling a lot trying to get our build server going. I am currently
I'm currently struggling to use UI elements in Interface Builder. I keep trying to
I'm currently struggling with one of the bindings I'm trying to add to my
I'm struggling to model a particular relationship with ActiveRecord. I currently have the following
I am struggling to find out if pushViewController retains the controller, currently I have
I am currently struggling with Maven: I have a complex project made of several
I am currently struggling with a really really strange issue. I have a telephone
My math classes are far behind, and I'm currently struggling to find a decent
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.

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.