PostgreSQL Update Table: Update the salary of an employee with a new value for some specific employees in HR database

6. Write a SQL statement to change the salary of an employee to 8000 whose ID is 105, if the existing salary is less than 5000.

Sample table: employees

Sample Solution:


UPDATE employees SET SALARY = 8000 
WHERE employee_id = 105 
AND salary < 5000;


See the result. Only the effected rows have been displayed.

postgres=# SELECT * FROM  employees 
AND employee_id = 105;

 employee_id | first_name | last_name |  email  | phone_number | hire_date  | job_id  | salary  | commission_pct | manager_id | department_id
         105 | David      | Austin    | DAUSTIN | 590.423.4569 | 1987-06-22 | IT_PROG | 8000.00 |           0.00 |        103 |            60
(1 row)

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a SQL statement to change the email column of the employees table with 'not available' for those employees who belongs to the 'Accounting' department.
Next: Write a SQL statement to change the job ID of the employee which ID is 118 to SH_CLERK if the employee belongs to a department which ID is 30 and the existing job ID does not start with SH.

What is the difficulty level of this exercise?

Follow us on Facebook and Twitter for latest update.