sql - How to insert all the rows with project name that not in table A to table A from table B -


sorry bad title, don't know how phrase question well. right have 2 table:

table a:

guid         project   state 1####        ###     active 2####        b ###     active 3####        c ###     active 4####        d ###     active 

table b resource table, there few columns, , 1 column project, thing wanna is:

if there project in table b not in table a, add table , give guid , inactive state.

but i'm not sure how implement this, tried several insert select, doesn't work, suppose need use exist condition?

you can use not in , sub-query. this:

insert tablea (....)    select      ....    tableb     project not in (select project tablea) 

this can done left join this:

insert tablea (....)    select      ....    tableb b    left join tablea on b.project = a.project    a.project null 

you can see how server software checking execution plans same both of these queries.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -