0

I have a problem with mysql query.

I have a table (Table_A) which has two columns(X & Y). I am trying insert values in column X & Y using subqueries from a different table.

INSERT INTO Table_A (X,Y) 
VALUES
((Select Col1 from tablex where Col2 is null),(Select Col1 from tablex where Col2 is null and Col3 is not null));

Getting this below error.

Error Code: 1242. Subquery returns more than 1 row

Is there any other way I can insert values to these columns from other table in one shot.

I can always run multiple insert statements, but that would be running multiple statements.

INSERT INTO Table_A (X) VALUES
(Select Col1 from tablex where Col2 is null)

INSERT INTO Table_A (Y) VALUES
(Select Col1 from tablex where Col2 is null and Col3 is not null)
anshuk_pal
  • 195
  • 1
  • 8
  • Forget about INSERT .. VALUES. Study INSERT .. SELECT. https://dev.mysql.com/doc/refman/8.0/en/insert-select.html – Akina Nov 16 '22 at 16:21

0 Answers0