Part 1 Multiple Queries
Part 1 Multiple Queries
1. Write a query for the HR department to produce the addresses of all the departments. Use the LOCATIONS
and COUNTRIES tables. Show the location ID, street address, city, state or province, and country in the
output. Use a NATURAL JOIN to produce the results.
2. The HR department needs a report of all employees. Write a query to display the last name, department
number, and department name for all the employees.
3. The HR department needs a report of employees in Toronto. Display the last name, job, department
number, and the department name for all employees who work in Toronto.
4. Create a report to display employees’ last name and employee number along with their manager’s last
name and manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively.
6. Create a report for the HR department that displays employee last names, department numbers, and all the
employees who work in the same department as a given employee. Give each column an appropriate label.
7. The HR department needs a report on job title and salaries. To familiarize yourself with the JOBS table, first
show the structure of the JOBS table. Then create a query that displays the name, job title, department
name, and salary for all employees.
DESC JOB_GRADES
SELECT e.last_name, e.job_id, d.department_name,
e.salary, j.grade_level
FROM employees e JOIN departments d
ON (e.department_id = d.department_id)
JOIN job_grades j
ON (e.salary BETWEEN j.lowest_sal AND j.highest_sal);
Part 2 Subqueries
8. The HR department needs a query that prompts the user for an employee last name. The query then
displays the last name and hire date of any employee in the same department as the employee whose
SELECT e.last_name, e.hire_date
FROM employees e JOIN employees davies
ON (davies.last_name = 'Davies')
WHERE davies.hire_date < e.hire_date;
9. name they supply (excluding that employee). For example, if the user enters Zlotkey, find all employees who
work with Zlotkey (excluding Zlotkey).
10. Create a report that displays the employee number, last name, and salary of all employees who earn more
than the average salary. Sort the results in order of ascending salary.
11. Write a query that displays the employee number and last name of all employees who work in a department
with any employee whose last name contains a u.
12. The HR department needs a report that displays the last name, department number, and job ID of all
employees whose department location ID is 1700.
Modify the query so that the user is prompted for a location ID.
13. Create a report for HR that displays the last name and salary of every employee who reports to King.
14. Create a report for HR that displays the department number, last name, and job ID for every employee in
the Executive department.
SELECT *
FROM DEPARTMENT;
In Natural Join, If there is no condition specifies then it returns the rows based on the common column
while In Inner Join, only those records will return which exists in both the tables.
II. REFERENCES
Hoffer, J.A., Prescott, M.B., McFadden, F.R. (2007). Modern Database Management 8th
Edition. New Jersey: Pearson Prentice Hall.