Home > OS >  Single query to update the flag in all the child tables
Single query to update the flag in all the child tables

Time:06-24

I want to update a flag in all the child tables based on the id which is a primary key in master table. I want to do it in single query how can I do it??

CodePudding user response:

UPDATE main
JOIN slave1 USING (id)
JOIN slave2 USING (id)
...
SET slave1.flag = 1,
    slave2.flag = 1,
...
WHERE main.id IN ( {ids list} )
...

CodePudding user response:

Example:

UPDATE Students SET flag = true WHERE id in (SELECT student.id from Students INNER JOIN Classes on students.classId = classes.id );

  • Related