Assessment LABEXERCISE4 Ubas
Assessment LABEXERCISE4 Ubas
EXERCISE
4
ADVANCED SQL
GJPRosales
Page |2
I. OBJECTIVES
Write the appropriate SQL statement for the following queries. The result of the queries will be
checked from your computer.
• Join–a relational operation that causes two or more tables with a common domain to be
combined into a single table or view
• Equi-join–a join in which the joining condition is based on equality between values in the
common columns; common columns appear redundantly in the result table
• Natural join–an equi-join in which one of the duplicate columns is eliminated in the result
table
• Outer join–a join in which rows that do not have matching values in common columns
are nonetheless included in the result table (as opposed to inner join, in which rows must
have matching values in order to appear in the result table)
• Union join–includes all columns from each table in the join, and an instance for each row
of each table
• The common columns in joined tables are usually the primary key of the dominant table
and the foreign key of the dependent table in 1:M relationships.
GJPRosales
Page |3
Example:
PART 1:
Scenario
The HR department needs your assistance in creating some queries.
Task
Write the appropriate SQL statement for the following queries. The result of the
queries will be checked from your computer.
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
GJPRosales
Page |4
ID, street address, city, state or province, and country in the output. Use a 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.
GJPRosales
Page |5
GJPRosales
Page |6
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.
5. Modify question#4 to display all employees including King, who has no manager.
Order the results by the employee number.
GJPRosales
Page |7
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.
GJPRosales
Page |8
Part 2 Subqueries
7. 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.
GJPRosales
Page |9
8. 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.
GJPRosales
P a g e | 10
9. Create a report for HR that displays the last name and salary of every employee
who reports to King.
GJPRosales
P a g e | 11
10. Create a report for HR that displays the department number, last name, and job
ID for every employee in the Executive department.
GJPRosales
P a g e | 12
V. REFERENCES
Hoffer, J.A., Prescott, M.B., McFadden, F.R. (2016). Modern Database Management
12th Edition, Prentice Hall.
Microsoft. (2012). Database Administration Fundamentals . USA: Wiley.
GJPRosales