Skip to content
Advertisement

Fill table (PK column A, PK column B) with table of elements B, where column A does not have B – list pair

So, to me comes Table2 (PK Text) filled with elements FIRST, SECOND, THIRD, FORTH. I need to insert this element to TABLE1 where these elements are missing.

TABLE1

So ID A misses FORTH

Should be inserted

B misses SECOND and FORTH and so on

Answer should be something like that

Advertisement

Answer

You can cross join the texts from table2 with the distinct ids availabel in table1 and filter on the missing tuples with a not exists condition, like so:

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