开发者

insert into table values from another table

开发者 https://www.devze.com 2023-03-06 00:09 出处:网络
I have 2 tables: Person and Item. I开发者_如何学Python just created a new column in the Item table called item_lab_fk.

I have 2 tables: Person and Item. I开发者_如何学Python just created a new column in the Item table called item_lab_fk.

I need to select the person_lab_fk values from the Person table and place it in the item_lab_fk column in the Item table.

I tried running the following piece of sql query but it's not working properly.

I would be grateful if someone would kindly show me where the error lies in the code below:

INSERT INTO item (`item_lab_fk`)
  SELECT person.person_lab_fk
  FROM person WHERE person.per_oid = item.item_created_by

Note that the item.item_created_by field is the person_id from the Person table.


This is hand typed and untested but should put you on the right path

UPDATE Item
SET Item.item_lab_fk = Person.person_lab_fk
FROM Item INNER JOIN Person ON Person.per_old = Item.item_created_by
0

精彩评论

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