0% found this document useful (0 votes)
67 views

Assessment LABEXERCISE4 Ubas

This document provides an exercise on advanced SQL involving joins and subqueries. The objectives are to perform different types of joins, add conditions, use subqueries to query unknown criteria, and find values that exist in one data set but not another. The experimental procedure involves using SQL statements to answer multiple queries on employee data, including producing addresses of departments using a join, reports on employees with department details, and subqueries to filter results based on average salary, employees reporting to King, and more. Supporting references are provided.

Uploaded by

John Rey Ubas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Assessment LABEXERCISE4 Ubas

This document provides an exercise on advanced SQL involving joins and subqueries. The objectives are to perform different types of joins, add conditions, use subqueries to query unknown criteria, and find values that exist in one data set but not another. The experimental procedure involves using SQL statements to answer multiple queries on employee data, including producing addresses of departments using a join, reports on employees with department details, and subqueries to filter results based on average salary, employees reporting to King, and more. Supporting references are provided.

Uploaded by

John Rey Ubas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Page |1

INFORMATION TECHNOLOGY AND INFORMATION SYSTEM


DEPARTMENT

ADVANCED DATABASE MANAGEMENT SYSTEM

EXERCISE

4
ADVANCED SQL

John Rey J. Ubas 29036


NAME SECTION
03/09/2023 03/10/2023
DATE PERFORMED DATE FINISHED

GJPRosales
Page |2

I. OBJECTIVES

At the end of this exercise, students must be able to:


a. Join tables using an equijoin
b. Performing outer and self-joins
c. Adding conditions
d. Creating subqueries to query values based on unknown criteria
e. Using subqueries to find out which values exist in one set of data and not in
another

II. BACKGROUND INFORMATION

Write the appropriate SQL statement for the following queries. The result of the queries will be
checked from your computer.

• Use a join to query data from more than one table:


SELECT table1.column, table2.column
FROM table1
[NATURAL JOIN table2] |
[JOIN table2 USING (column_name)] |
[JOIN table2
ON (table1.column_name = table2.column_name)]|
[LEFT|RIGHT|FULL OUTER JOIN table2
ON (table1.column_name = table2.column_name)]|
[CROSS JOIN table2];

• 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:

Processing Multiple Tables Using Subqueries

• Subquery–placing an inner query (SELECT statement) inside an outer query


• Options:
– In a condition of the WHERE clause
– As a “table” of the FROM clause
– Within the HAVING clause
• Subqueries can be:
– Noncorrelated–executed once for the entire outer query
– Correlated–executed once for each row returned by the outer query
Example

III. EXPERIMENTAL PROCEDURE

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.

PROVIDE A SCREENSHOT OF THE SCRIPT AND THE OUTPUT PER STEP

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

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

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.

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.

IV. QUESTION AND ANSWER

1. Cite 3 importance on using join statements. Support your statements.

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

You might also like