开发者

insert into table when value doesnt exist?

开发者 https://www.devze.com 2023-01-11 09:04 出处:网络
I am trying to insert all entries in table b into table A when the status is <32 and it isnt already in ta开发者_JAVA百科ble a.

I am trying to insert all entries in table b into table A when

  1. the status is <32 and

  2. it isnt already in ta开发者_JAVA百科ble a.

The 2nd part is what is giving me trouble. I wrote a subquery and my gut says i did it wrong and i also notice it taking a very long time to execute

how do i write this rest of the query?

table a { int id, fId }
table b { int id, status; string data; }

insert into a(fId) select id from b where status<32 and ???


insert into a(fId) 
  select id
  from b
  where status<32 
    and id not in (select fId from a)
0

精彩评论

暂无评论...
验证码 换一张
取 消