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

  • Home
  • SEARCH
  • 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 8771391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:46:30+00:00 2026-06-13T17:46:30+00:00

Say I have 3 tables, each with a field foo . How do I

  • 0

Say I have 3 tables, each with a field foo. How do I get the following records:

  1. All records where the value of foo exist in all 3 tables?
  2. All records where the value of foo exist in any 2 tables?
  3. All records where the value of foo exist in 1 table only?

foo is UNIQUE.

My attempt for #1:

SELECT a.foo
FROM   a
WHERE  a.foo IN (SELECT b.foo
                 FROM   b
                 WHERE  b.foo IN (SELECT c.foo
                                  FROM   c)) 

For #2, I think I need to do something similar to #1, but for 2 tables at a time {a,b}, {b,c}, {a,c} – and then UNION it? Not sure.

For #3, no clue.

UPDATE: Sample Data

Table1
 - foo-a
 - foo-b
 - foo-c

Table2
 - foo-a
 - foo-b

Table3
 - foo-a
 - foo-c
 - foo-d

For #1 question, there is 1 record that exist in all 3 tables: foo-a. For #2 question, there are 2 records that exist in 2 tables: foo-b (in Table1 and Table2) and foo-c (in Table1 and Table3). For #3 question, there is 1 record that exist in only 1 table: foo-d.

  • 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-13T17:46:31+00:00Added an answer on June 13, 2026 at 5:46 pm

    Since FOO is unique,

    For No. 1,

    SELECT Foo
    FROM
        (
            SELECT Foo FROM table1
            UNION ALL
            SELECT Foo FROM table2
            UNION ALL
            SELECT Foo FROM table3
        ) a
    GROUP BY Foo
    HAVING COUNT(*) = 3
    

    For No. 2,

    SELECT Foo
    FROM
        (
            SELECT Foo FROM table1
            UNION ALL
            SELECT Foo FROM table2
            UNION ALL
            SELECT Foo FROM table3
        ) a
    GROUP BY Foo
    HAVING COUNT(*) = 2
    

    For No. 3,

    SELECT Foo
    FROM
        (
            SELECT Foo FROM table1
            UNION ALL
            SELECT Foo FROM table2
            UNION ALL
            SELECT Foo FROM table3
        ) a
    GROUP BY Foo
    HAVING COUNT(*) = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have three tables, a table of users, a table of around 500
Say I have three tables: Fruit (Table 1) ------ Apple Orange Pear Banana Produce
Lets say I have two tables tblA ( tableAID INT IDENTITY(1,1), foo VARCHAR(100)) tblB
Say I have two tables, Parent and Child. Parent has a MaxChildren (int) field
Say I have a table with 5000 records, and another table containing a list
Lets say I have a simple many-to-many table between tables table1 and table2 that
Say I have two tables, author and book. Each author can have multiple books,
Say we have two tables in an MS Access db: Service Users: | ID
Say I have two tables called A (fields: id, phase, name) and B(fields: id,
Lets say I have five tables named table1, table2 ... table5. I have already

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.