0
INSERT INTO (
    SELECT student_info.Student_Name,scores.Final
    FROM student_info 
    INNER JOIN scores ON scores.Student_id=student_info.Student_id 
        AND scores.Subject_id=1)
(Student_Name,Final) VALUES("a",1)

Something like this.....What i want to achieve is that i want to add a new row to the queried result which will display the average of the columns above it.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Sai
  • 1

2 Answers2

1

Use UNION to combine the results of two queries into a single result:

SELECT student_info.Student_Name,scores.Final
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
    AND scores.Subject_id=1

UNION

SELECT "a", AVG(scores.Final)
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
    AND scores.Subject_id=1
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

if you need an insert select you could use this way

INSERT INTO your_table_name  (Student_Name,Final)
SELECT student_info.Student_Name,scores.Final
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
AND scores.Subject_id=1

and eventually if need a added row you can add an union clause with the literal value to your select

INSERT INTO your_table_name   (Student_Name,Final)
SELECT student_info.Student_Name,scores.Final
FROM student_info 
INNER JOIN scores ON scores.Student_id=student_info.Student_id 
AND scores.Subject_id=1
union all  
select "a", 1
from dual;
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
  • You need a table name after `INSERT INTO`. – Barmar Mar 25 '17 at 09:38
  • @scaisEdge In my case, I wish to insert row into a queried result.......is it possible to name the queried result?? – Sai Mar 26 '17 at 05:49
  • [Student_Name,Final] [a, 25] [b, 58] [c, 67] [d, 46] After my query this is my result(^) and i wish to add a row in this saying Average 49 – Sai Mar 26 '17 at 05:51