如何使用Select-Statements将值插入MYSQL表

时间:2022-09-25 16:09:27

Okay, This one is pretty simmilar to my last one, but I don't get it...!

好的,这个与我的上一个非常相似,但我不明白......!

I am trying the following:

我正在尝试以下方面:

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 from Germany and thx for your answers!

来自德国的Greetz和你的答案!

1 个解决方案

#1


9  

Very close - use:

非常接近 - 使用:

INSERT INTO TABLE_B
SELECT column_1, column_2, column_3 
  FROM TABLE_A
 WHERE id = 1

..assuming there are only three columns in TABLE_B. Otherwise, specify the columns being inserted into:

..假设TABLE_B中只有三列。否则,指定要插入的列:

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

#1


9  

Very close - use:

非常接近 - 使用:

INSERT INTO TABLE_B
SELECT column_1, column_2, column_3 
  FROM TABLE_A
 WHERE id = 1

..assuming there are only three columns in TABLE_B. Otherwise, specify the columns being inserted into:

..假设TABLE_B中只有三列。否则,指定要插入的列:

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