0

I am trying to execute a query which is something like:

update table set column=(select column1 from table1);

I just want to store the value from other table to my column

but when i try my sql query it says

ERROR 1242 (21000): Subquery returns more than 1 row

definitely this means my table1 contains more than 1 row so i want to know that is there any way to store data into column from other table with multiple row.

or basically saving content of other table as a text something like

 update table set column='Data in text from other table';
2
  • This is because your subquery (select column1 from table1) returns more than 1 row as the error message says. You can use limit 0,1 to get it working. But if this your expected result, I cannot tell you. Commented Mar 4, 2016 at 13:03
  • I removed the extraneous database tags. Feel free to add the tag for the database you are using. Commented Mar 4, 2016 at 13:04

3 Answers 3

1

You probably need a correlation clause:

update table
    set column = (select column1 from table1 where table.col = table1.col);

You need to decide what column(s) are used for the correlation.

Sign up to request clarification or add additional context in comments.

1 Comment

i want to add all columns not only one column i want all data from table is this possible
0

it will work as i am getting your requirement.Please let me know if your requirement is other i ll make changes in query

update table_name t1
inner join table1 t2 on t1.id =t2.id
set column =column1

Comments

0

Your nested query returns multiple rows so you encountered this error. Try in this way

UPDATE FirstTable
SET FirstTable.ColumnName =tbl2.ColumnName 
FROM SecondTable tbl2 WHERE tbl2.Id = FirstTable.Id

There should be a common id or something that will help to find exact row.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.