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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:44:40+00:00 2026-05-15T10:44:40+00:00

I have four tables TableA: id1 id2 id3 value TableB: id1 desc TableC: id2

  • 0

I have four tables

TableA:

  • id1
  • id2
  • id3
  • value

TableB:

  • id1
  • desc

TableC:

  • id2
  • desc

TableD:

  • id3
  • desc

What I need to do is to check if all combinations of id1 id2 id3 from table B C and D exist in the TableA. In other words, table A should contain all possible combinations of id1 id2 and id3 which are stored in the other three tables.

  • 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-15T10:44:41+00:00Added an answer on May 15, 2026 at 10:44 am

    This query evaluates all combinations of id1, id2 and id3 (the cross join) and finds which combinations are not present in table a.

    select b.id1, c.id2, d.id3 from
     TableB b cross join TableC c cross join TableD d WHERE NOT EXIST
     (select 1 FROM TableA a WHERE a.id1=b.id1 AND a.id2=c.id2 AND a.id3=d.id3)
    

    EDIT: With an RIGHT JOIN

    SELECT allPerms.id1, allPerms.id2, allPerms.id3 FROM a RIGHT JOIN (select b.id1, c.id2, d.id3 from
     TableB b cross join TableC c cross join TableD) allPerms
     ON a.id1=allPerms.id1 AND a.id2=allPerms.id2 AND a.id3=allPerms.id3
     WHERE a.id1 IS NULL
    

    The two are pretty much the same. Since we are not actually fetching values from the joined table, some people prefer the first approach, since it captures the intent and spirit of the query. The second version is more “implementation oriented”. A good optimizer will produce an efficient plan for both, but on some lesser RDBMSs, the second version will run faster.

    With a predefined set for table D – id3 has values (2,5,6)

    select b.id1, c.id2 from
     TableB b cross join TableC c WHERE NOT EXIST
     (select 1 FROM TableA a WHERE a.id1=b.id1 AND a.id2=c.id2 AND a.id3 IN (2,5,6))
    

    But, this doesn’t give you the id3 that is missing in the table A row. For that, I think the simplest is to emulate the table via a union, e.g.

    select b.id1, c.id2, d.id3 from
     TableB b, TableC c, (select 2 id3 union select 5 union select 6) d 
    WHERE NOT EXIST
     (select 1 FROM TableA a WHERE a.id1=b.id1 AND a.id2=c.id2 AND a.id3=d.id3)
    

    (This is still using cross join – it’s implied if tables are separated by commas.)

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

Sidebar

Related Questions

I have four tables: Messages, MessageCategory, MessageStatus and MessageLevel. MessageCategory, MessageStatus and MessageLevel all
I have table dates as following dates one two three four date1 id1 id2
I have four tables containing exactly the same columns, and want to create a
Let's say I have four tables: PAGE , USER , TAG , and PAGE-TAG
I have four flags Current = 0x1 Past = 0x2 Future = 0x4 All
I have three tables, table one (tableA) containing users data like name and email,
I have two tables: 1. tableA is a list of records with many columns.
I have four tables: - Client with PK ClientID. - Destination with PK DestinationID.
I have four tables: RootNode // Will return multiple root nodes SubNode // Will
Say I have four tables: ------------- features -------------- id: int name: varchar ------------------------------------- --------

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.