Reputation: 849
My requirement is to insert record from selected query result in to new table.
My query is
SELECT
a.Section_name, b.sectionname, a.SubQno, b.Qno, a.ans, b.Answ,
a.Exame_id, b.Exame_id AS Expr1, b.User_id, b.Start_time, b.End_time
FROM Question AS a
INNER JOIN Solve_Student_question AS b ON a.SubQno = b.Qno AND a.Section_name = b.sectionname
WHERE (b.User_id = 'gopal ram51765078')
Now this query result stored in to Temp
table. How can I do this?
Upvotes: 0
Views: 57
Reputation: 67
insert into [temptablename] (comma-separated list of column names)
(your Select Query Here)
Upvotes: 0
Reputation: 1
declare
cursor C is
select a.Section_name, b.sectionname, a.SubQno, b.Qno, a.ans,
b.Answ, a.Exame_id, b.Exame_id AS Expr1, b.User_id, b.Start_time, b.End_time
FROM Question AS a INNER JOIN
Solve_Student_question AS b ON a.SubQno = b.Qno AND a.Section_name = b.sectionname
WHERE (b.User_id = 'gopal ram51765078');
begin
for i in C
insert into tablename(Column1,Column2,Column3)
values(i.column1,i.Column2,i.Column3);
end loop;
Exit when last.record = 'TRUE';
end;
`
`
Upvotes: 0
Reputation: 21757
You can use the Insert Into ... Select
idiom like so:
INSERT INTO TempTable
(...) --Columns
SELECT
a.Section_name, b.sectionname, a.SubQno, b.Qno, a.ans, b.Answ, a.Exame_id, b.Exame_id AS Expr1, b.User_id, b.Start_time, b.End_time
FROM Question AS a INNER JOIN
Solve_Student_question AS b ON a.SubQno = b.Qno AND a.Section_name = b.sectionname
WHERE (b.User_id = 'gopal ram51765078')
Upvotes: 3