如何通过使用选择语句将值插入到MYSQL表中 [英] How to insert values into an MYSQL-Table by using Select-Statements
本文介绍了如何通过使用选择语句将值插入到MYSQL表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,这个和我的最后一个很相似,但我不能得到它...!
Okay, This one is pretty simmilar to my last one, but I don't get it...!
我尝试以下:
Insert into table b
(Select column_1 from table_a where ID = 1),
(Select column_2 from table_a where ID = 1),
0,
(Select column_3 from table_a where ID = 1);
但我总是得到语法错误...!
我认为这是相当合乎逻辑的我想做的。
But I always get a syntax-error...! I think it's quite logical what I'm trying to do.
来自德国的Greetz和thx的答案!
Greetz from Germany and thx for your answers!
推荐答案
非常接近 - 使用:
INSERT INTO TABLE_B
SELECT column_1, column_2, column_3
FROM TABLE_A
WHERE id = 1
..假设 TABLE_B
中只有三列。否则,指定要插入的列:
..assuming there are only three columns in TABLE_B
. Otherwise, specify the columns being inserted into:
INSERT INTO TABLE_B
(column_1, column_2, column_3)
SELECT column_1, column_2, column_3
FROM TABLE_A
WHERE id = 1
如果需要,您也可以使用静态定义的值:
And, if need be--you can use statically defined values as well:
INSERT INTO TABLE_B
(column_1, column_2, column_3, column_4)
SELECT column_1, column_2, 0, column_3
FROM TABLE_A
WHERE id = 1
这篇关于如何通过使用选择语句将值插入到MYSQL表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文