Introduction to Database Systems (SWE-209L) SSUET/QR/114
Lab # 4: Sorting Data, Set Operators
LAB # 4
SORTING DATA, SET OPERATORS
OBJECTIVE: Sort the rows that are retrieved by a query and use SET Operators.
LAB TASKS:
Employees(employee_id, first_name, last_name, email, phone_number, hire_date, job_id,
salary, commission_pct, manager_id, department_id)
1. From the following schema, write a SQL query to find those employees whose first
name contains the letters R, A, or N. Sort the result-set in ascending order by salary.
Return all fields.
Query:
SYED TAYYAB RAZA ZAIDI (2020-SE-272) 27
Introduction to Database Systems (SWE-209L) SSUET/QR/114
Lab # 4: Sorting Data, Set Operators
Output:
2. From the following schema, write a SQL query to find those employees who earn
above 21000 or the fifth character in their phone number is 8.. Sort the result-set in
ascending order by last name. Return full name (first name and last name), hire date,
commission percentage, email, and telephone separated by '-', and salary.
Query:
Output:
SYED TAYYAB RAZA ZAIDI (2020-SE-272) 28
Introduction to Database Systems (SWE-209L) SSUET/QR/114
Lab # 4: Sorting Data, Set Operators
Orders(ord_no, purch_amt, ord_date, customer_id, salesman_id)
Salesman (salesman_id, name, city, commission)
Customer (customer_id, cust_name, city, grade, salesman_id)
SYED TAYYAB RAZA ZAIDI (2020-SE-272) 29
Introduction to Database Systems (SWE-209L) SSUET/QR/114
Lab # 4: Sorting Data, Set Operators
3. From the following table, write a SQL query to find those salespersons generated
the largest and smallest orders on each date. Return salesperson ID, name, order no.,
highest on/ lowest on, order date.
QUERY:
OUTPUT:
SYED TAYYAB RAZA ZAIDI (2020-SE-272) 30
Introduction to Database Systems (SWE-209L) SSUET/QR/114
Lab # 4: Sorting Data, Set Operators
4. From the following tables, write a SQL query to find those salespersons who have
same cities where customer lives as well as do not have customers in their cities and
indicate it by ‘NO MATCH’. Sort the result set on 2nd column (i.e. name) in
descending order. Return salesperson ID, name, customer name, commission.
QUERY:
OUTPUT:
SYED TAYYAB RAZA ZAIDI (2020-SE-272) 31