tags:

views:

27

answers:

1

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 table 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 ???
+2  A: 

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

thelost
i did a select count(), `<rest of query>` and the count is the same as without that statement. So this appears to be wrong. also wouldnt = id be from a rather then b?(maybe thats what you wanted but the results still appears to be wrong)
acidzombie24
so you want ids from B to A or from A to B ? I guess the 1st. Also it would be good to verify the data and o the count value which might lead to erroneously conclusions.
thelost
I must have misread. I could have sworn there was a where statement in the subquery but the edit doesnt show it. The answer is verified correct now :). My bad by writing that first comment.
acidzombie24