SQL UPDATE query to update columns in multiple tables using INNER & LEFT JOIN with GROUP BY query

preview_player
Показать описание

Updating second table by using data from first table. We have three columns with marks in three subjects ( student3 table ) , we will add these three subjects marks and update the same in another table having the same student id.
Before this we will set all marks column value to 0
UPDATE student3_total SET mark=0
Now we will apply SQL query to update the mark column in second table ( student3_total)
UPDATE studnt3_total, student3 SET mark=(math+social+science) WHERE s_id=id
We can use LEFT JOIN also
UPDATE student3_total LEFT JOIN student3 ON s_id=id SET mark= (math+social+science)
Using INNER JOIN
UPDATE student3_total LEFT JOIN student3 ON s_id=id SET mark= (math+social+science)
We can update same table with average value also. Use the student3_avg table for this .
Adding average mark of each student
update student3_avg a
LEFT JOIN (select id, sum(social + math + science )/3 as number
FROM student3_avg group by id)
Adding class average
update student3_avg a LEFT JOIN
(select class, avg(average) as number from
student3_avg group by class)
Рекомендации по теме
Комментарии
Автор

Is there a way to update rows of student3 and student3_total table using single query?

prachip