update employees set salary=salary*10/100+salary
where EmployeeID (select EmployeeID from employees where salary<2000)
Asked
Active
Viewed 45 times
-4

Gordon Linoff
- 1,242,037
- 58
- 646
- 786
-
21. Don't use bold unless needed 2. What exactly is your problem? 3. MySQL and SQL Server are not the same thing. Which one are you actually using? – John Conde Sep 02 '14 at 15:34
-
3This update will effectively do NOTHING. 10/100 will result in 0 because of integer division. Then through the order of operations the net result will be that no value is actually changed. If the idea is to give everyone a 10% increase you could do the math a LOT simpler with salary * 1.1 – Sean Lange Sep 02 '14 at 15:41
1 Answers
1
Try the IN
update employees set salary=salary*10/100+salary
where EmployeeID IN (select EmployeeID from employees where salary<2000)
As suggested by Lamak
update employees set salary=salary*10/100+salary
where salary<2000
Another option.
update employees e1 set salary=salary*10/100+salary
where EXISTS (select NULL
from employees e2
where e2.salary<2000
and e1.EmployeeID = e2.EmployeeID
)
The EXISTS
is overkill in your case but may be very usefull.
You should read about it. here's a good start :-) .
In your case you should use only the condition salary<2000
in the WHERE clause.
-
4
-
2See my comment above about integer math. As coded, this update will do nothing. – Sean Lange Sep 02 '14 at 15:41