Skip to content
Advertisement

Find sum from 2 tables and write code in php [closed]

This is the query image: this is the query image

This result should appear as follows: this result should appear as follows

This is my query: select id, name, total where student.id= marks.sutdent_id

Advertisement

Answer

You should group on the student id and name and sum the marks:

SELECT   s.id, s.name, SUM(e.marks) AS total
FROM     student s
JOIN     exam    e ON s.id = e.stud_id
GROUP BY s.id, s.name
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement