[英]MYSQL: How to copy an entire row from one table to another in mysql with the second table having one extra column?
[英]How to copy an entire row from one table to another in mysql with the second table having a modified field
我正在一個項目中,我需要將舊表中包含200多個字段的許多行導入到新表中,但是id字段必須以“ 5”開頭。
我正在使用此SQL語句:
INSERT INTO brinkoet_dev.property
SELECT liveprop.*
FROM brinkoet_live.property liveprop
WHERE listing_office='Brink';
但沒有明顯的方法可以更改現有字段的內容。
在新表中,將“ id”字段重命名為“ id_old”。 在新表中,在此表的末尾添加“ id”字段。 然后,您可以執行以下操作:
INSERT INTO brinkoet_dev.property
SELECT liveprop.*, CONCAT(5, liveprop.id)
FROM brinkoet_live.property liveprop
WHERE listing_office='Brink';
完成后,只需從新表中刪除id_old字段即可。
嘗試這個:
INSERT INTO brinkoet_dev.property
SELECT concat(5, liveprop.ID), field2, field3
FROM brinkoet_live.property liveprop
WHERE listing_office='Brink'
其中field2
和field3
是liveprop
表的其余字段(不包括ID
)。
這是一個小提琴供您使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.