0

I have two tables, Table A has user Id and 5 different product columns(empty, to be filled by count ). Table B has timestamp user id and product id ( purchased at time t). This code id giving error

update table_A as table_A 
  set Count_Product_1 = (select count(product_ID)
                         from Table_B inner join Table_A 
                           on Table_A.User_ID=Table_B.User_ID 
                         where Product_ID = 'Unique_identifier_product_1');

error: You cannot reopen Table_A for update access with member-level control because Table_A is in use by you in resource environment SQL

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
Zyerr Dwij
  • 13
  • 1

1 Answers1

3

I am guessing that you want a correlated subquery, not a general subquery. Perhaps this does what you want:

update table_A as a 
    set Count_Product_1 = (select count(b.product_ID)
                           from Table_B b
                           where a.User_ID = b.User_ID and
                                 b.Product_ID = 'Unique_identifier_product_1'
                          );

This just seems like a more reasonable query.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786