w3resource

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:

Code:

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

Output:

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

postgres=# SELECT * FROM  employees 
WHERE  SALARY = 8000 
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.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming