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 the email column of employees table with 'not available' for those who are in 'Accounting' department

MySQL Update Table Statement: Exercise-5 with Solution

Write a SQL statement to change the email column of employees table with 'not available' for those employees who belongs to the 'Accounting' department.

Here is the sample table employees.


Here is the sample table departments.


UPDATE employees 
SET email='not available'
WHERE department_id=(
SELECT department_id 
FROM departments 
WHERE department_name='Accounting');

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 |
+-------------+------------+-----------+---------------+--------------+------------+------------+----------+----------------+------------+---------------+
|         205 | Shelley    | Higgins   | not available | 515.123.8080 | 1987-09-30 | AC_MGR     | 12000.00 |           0.00 |        101 |           110 |
|         206 | William    | Gietz     | not available | 515.123.8181 | 1987-10-01 | AC_ACCOUNT |  8300.00 |           0.00 |        205 |           110 |
+-------------+------------+-----------+---------------+--------------+------------+------------+----------+----------------+------------+---------------+


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 employees table with 'not available' for those employees whose department_id is 80 and gets a commission is less than .20%.
Next: Write a SQL statement to change salary of employee to 8000 whose ID is 105, if the existing salary is less than 5000.

What is the difficulty level of this exercise?