-4
update employees set salary=salary*10/100+salary
where EmployeeID (select EmployeeID from employees where salary<2000)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 2
    1. 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
  • 3
    This 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 Answers1

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.

Community
  • 1
  • 1
Luc M
  • 16,630
  • 26
  • 74
  • 89