0

我有两个图像表,现在我喜欢将所有图像打包在一个表中并通过外键 fk_image 引用它:

还:

Table1: ('id_system' , 'logo_image_raw', 'fk_image')
Table2: ('id_image', 'image_raw_data')

如何将 logo_image_raw 复制/移动到表 2 的“image_raw_data”并在 fk_image 中反映其 id_image?

4

2 回答 2

1

你可以这样做..

 INSERT INTO table2
 SELECT table1.fk_image, table1.logo_image_raw
 FROM table1, table2 WHERE table1.fk_image = table2.id_image
于 2013-01-23T13:05:52.423 回答
1

做就是了INSERT...INTO SELECT

INSERT  INTO table2 (id_image, image_raw_data)
SELECT  fk_image, logo_image_raw
FROM    table1 

如果该列为image_raw_datanull 但您已经拥有id_image,则需要加入表以便获取每个 ID 的特定图像,

UPDATE  table2 b 
        INNER JOIN table1 a
           ON a.fk_image = b.id_image
SET     b.image_raw_data = a.logo_image_raw
于 2013-01-23T12:55:41.823 回答