[英]mysql copy data from one table to another using foreign key
inputPreviewOffsetLeft
, inputPreviewOffsetTop
, inputPreviewSizeWidth
, inputPreviewSizeHeight
are present in the display_preview
table and display
. inputPreviewOffsetLeft
、 inputPreviewOffsetTop
、 inputPreviewSizeWidth
、 inputPreviewSizeHeight
存在于display_preview
表和display
中。 display_preview
has a foreign key displayId
on display
table. display_preview
在display
表上有一个外键displayId
。
INSERT INTO display_preview b (b.inputPreviewOffsetLeft, b.inputPreviewOffsetTop, b.inputPreviewSizeWidth, b.inputPreviewSizeHeight)
SELECT bd.inputPreviewOffsetLeft, bd.inputPreviewOffsetTop, bd.inputPreviewSizeWidth, bd.inputPreviewSizeHeight
FROM display
INNER JOIN display bd on bd.id = b.displayId
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b (b.inputPreviewOffsetLeft, b.inputPreviewOffsetTop, b.inputPreviewSizeWidth...' at line 1
You don't need to get INSERT
table an alias name and I think you might want to use INSERT INTO... SELECT
on display_preview
and display
您不需要为
INSERT
表获取别名,我想您可能想在display_preview
和display
上使用INSERT INTO... SELECT
you can try the below query您可以尝试以下查询
INSERT INTO display_preview (inputPreviewOffsetLeft,inputPreviewOffsetTop, inputPreviewSizeWidth, inputPreviewSizeHeight)
SELECT bd.inputPreviewOffsetLeft, bd.inputPreviewOffsetTop, bd.inputPreviewSizeWidth, bd.inputPreviewSizeHeight
FROM display_preview b
INNER JOIN display bd on bd.id = b.displayId
EDIT编辑
If you want to do UPDATE... JOIN
you can try this.如果你想
UPDATE... JOIN
你可以试试这个。
UPDATE display_preview b
INNER JOIN display bd on bd.id = b.displayId
SET
b.inputPreviewOffsetLeft = bd.inputPreviewOffsetLeft,
b.inputPreviewOffsetTop = bd.inputPreviewOffsetTop,
b.inputPreviewSizeWidth = bd.inputPreviewSizeWidth ,
b.inputPreviewSizeHeight = bd.inputPreviewSizeHeight
For more detail you can refer to MySQL UPDATE JOIN更多详情可以参考MySQL UPDATE JOIN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.