Activity3 Subquery Vacal
Activity3 Subquery Vacal
In this Insert Subquery, I built a back-up table with no insert values, and the data from the
employees table will be duplicated to the back-up table that I made using the Insert Subquery.
In this Insert Subquery, I inserted only one record the column job_name with connected to the
column with Job name Dean.
UPDATE SUBQUERY
UPDATE department_bkp
SET dep_location ="Topaz Bldg"
WHERE dep_location IN (SELECT dep_location from department)
In this Update Subquery, the column dep_location we set the data to “Topaz Bldg” so now every
department has the same location.
UPDATE employees_bkp
set salary = salary + 500
WHERE emp_id IN(SELECT emp_id FROM employees WHERE emp_id >=2)
As you can see, all the data in salary column is greater than equal to two so it means all the
data in salary column will be updated and added 500 each.
DELETE SUBQUERY
In this DELETE SUBQUERY, You will see that 1 row is affected and it is deleted from the table
DELETE FROM salary_grade_bkp WHERE grade IN (SELECT grade from salary_grade WHERE
grade >=1 or grade>=2)
As you can see no data left in the columns because if the column grade is greater than equal to 1
or greater than equal to 2 that row will be deleted.
EXIST SUBQUERY
8
In this EXIST SUBQUERY, you will see that the data in column from dep_id and emp_name are
exist from the table employees.
SELECT dep_id,dep_name
from department
WHERE EXISTS (SELECT * FROM employees WHERE employees.dep_id = department.dep_id)
The data in columns Department ID and Department name from the table employees have
been found in this EXIST SUBQUERY.
SELECT dep_id,emp_name
from employees
WHERE NOT EXISTS (SELECT * FROM department WHERE department.dep_id =
employees.dep_id)
In this NOT EXIST SUBQUERY, you will see that the data in column from the dep_id and
emp_name are not existed from the table employees.
SELECT dep_id,dep_name
from department
WHERE NOT EXISTS (SELECT * FROM employees WHERE employees.dep_id =
department.dep_id)
In this EXIST SUBQUERY, you will see that the data in columns of department id and
department name from the table employees do not exist.