Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL Update Table Statement Exercises: Change job ID of employee of ID is 118, to SH_CLERK if the employee in the department_id 30 and the job ID not started with SH

MySQL Update Table Statement: Exercise-7 with Solution

Write a SQL statement to change job ID of employee which ID is 118, to SH_CLERK if the employee belongs to department, which ID is 30 and the existing job ID does not start with SH.

Here is the sample table employees.


UPDATE employees SET JOB_ID= 'SH_CLERK' 
WHERE employee_id=118 
AND department_id=30 
AND NOT JOB_ID LIKE 'SH%';

Let execute the above code in MySQL 5.6 command prompt

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

+-------------+------------+-----------+---------+--------------+------------+----------+---------+----------------+------------+---------------+
| EMPLOYEE_ID | FIRST_NAME | LAST_NAME | EMAIL   | PHONE_NUMBER | HIRE_DATE  | JOB_ID   | SALARY  | COMMISSION_PCT | MANAGER_ID | DEPARTMENT_ID |
+-------------+------------+-----------+---------+--------------+------------+----------+---------+----------------+------------+---------------+
|         118 | Guy        | Himuro    | GHIMURO | 515.127.4565 | 1987-07-05 | SH_CLERK | 2600.00 |           0.00 |        114 |            30 |
+-------------+------------+-----------+---------+--------------+------------+----------+---------+----------------+------------+---------------+


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

Previous: Write a SQL statement to change salary of employee to 8000 whose ID is 105, if the existing salary is less than 5000.
Next: Write a SQL statement to increase the salary of employees under the department 40, 90 and 110 according to the company rules that, salary will be increased by 25% for the department 40, 15% for department 90 and 10% for the department 110 and the rest of the departments will remain same.

What is the difficulty level of this exercise?