0

I want to fetch data from student and teacher tables and insert into another table. but when I try to do that I am getting below error

@delimiter %%%;
BEGIN
 DECLARE name CHAR (3);
 DECLARE subject VARCHAR(25);
 DECLARE ID DECIMAL(19,0);
 DECLARE teacher_name VARCHAR(25);          
 
 insert into temp_table(std_name, subject, std_id, teacher_name) values (
SELECT std.name, std.subject, std.ID, tr.teacher_name FROM Student std inner join teacher tr on std.subject = tr.subject); 

 END%%%
    @delimiter ;
%%%

Result

[Code: -811, SQL State: 21000] The result of a scalar fullselect, SELECT INTO statement, or VALUES INTO statement is more than one row.. SQLCODE=-811, SQLSTATE=21000, DRIVER=4.22.29

Subathra
  • 13
  • 5
  • The syntax is `INSERT INTO t (c1, c2, c3) SELECT ...`. I.e. no VALUES, no parentheses. – jarlh Feb 14 '23 at 14:07
  • [Code: -803, SQL State: 23505] One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "temp-table" from having duplicate values for the index key.. SQLCODE=-803, SQLSTATE=23505, DRIVER=4.22.29 – Subathra Feb 14 '23 at 14:35

0 Answers0