开发者

insert into table when value doesnt exist?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜