I am trying to Insert data from a table1 into table2
insert into table2(Name,Subject,student_id,result)
select (Name,Subject,student_id,result)
from table1;
Key for table2 is student_id.
Assume that there are not any duplicates.
I get the error: MySQL error 1241: Operand should contain 1 column(s)
There are only four columns in table2.
Just remove the
(
and the)
on your SELECT statement:Another way to make the parser raise the same exception is the following incorrect clause.
The nested
SELECT
statement in theIN
clause returns two columns, which the parser sees as operands, which is technically correct, since the id column matches values from but one column (role_id) in the result returned by the nested select statement, which is expected to return a list.For sake of completeness, the correct syntax is as follows.
The stored procedure of which this query is a portion not only parsed, but returned the expected result.
Syntax error, remove the
( )
fromselect
.