How to insert values โ€‹โ€‹into a MYSQL table using Select-Statementments

Well, this is very similar to my last, but I do not understand ...

I am trying to do 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 thanks for your answers!

+3
source share
1 answer

Very close - use:

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

.. assuming that TABLE_Bthere are only three columns in. Otherwise, specify the columns inserted in:

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 necessary, you can also use statically defined values:

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
+9
source

Source: https://habr.com/ru/post/1769022/


All Articles