Skip to content
Advertisement

Data query to keep the common data

I have a table

Table 1 : It the final table contains all data . ID and IDS are composite key

table 2 : Its a pre final table which will upcoming data with incomplete information

EXPECTED RESULT : Some IDs (ID+IDS) are in Table 1 and some are in Table 2 . I need to compare the data of table 1 and table 2 . The rule is Keep the common data with Table 1 information Keep the new row with (id+IDS) which is in table 2 but not in table 1

for eg;

  1. (15100 + PL35) is in table 2 but not in table 1 then it will remain
  2. (1516 + PL35) is common in both then the row from table 1 will remain.
  3. ( 151511 + PL36) is also common hence will remain .
  4. The data (ID +IDs) which is not in table 2 but in table 1 is not needed.

SO far I am only think about this

Advertisement

Answer

Use INTERSECT, named after the equivalent set operation.

EDIT In answer to your question, you can wrap this in a CTE and then join back onto table1.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement