first i search name who teaches more than 2 courses
select i.name, count(*) teaches from instructor i
inner join teaches t on i.id = t.id
group by name
having count(*)>=2;
and it’s working so i want to raise salary with these results
update i set salary = salary*1.05
from instructor i
inner join teaches t on i.id = t.id
group by name having count(*)>=2;
but error in SQL syntax; how to fix it ?
>Solution :
I would use an update join here:
UPDATE instructor t1
INNER JOIN
(
SELECT i.id
FROM instructor i
INNER JOIN teaches t ON i.id = t.id
GROUP BY i.id
HAVING COUNT(*) > 1
) t2
ON t2.id = t1.id
SET
salary = 1.05 * salary;