Set Operators
Set Operators
Set Operators
SELF TEST
Describe the Set Operators
1. Which of these set operators will not sort the rows? (Choose the best answer.)
A. INTERSECT
B. MINUS
C. UNION
D. UNION ALL
2. Which of these operators will remove duplicate rows from the final result? (Choose all that apply.)
A. INTERSECT
B. MINUS
C. UNION
D. UNION ALL
The columns EMP.EMPNO and EX_EMP.EMP_ID are integer; the column EMP.HIRED is
timestamp; the columns EX_EMP.HIRED and EX_EMP.FIRED are date. Why will the state-
ment fail? (Choose the best answer.)
A. Because the columns EMPNO and EMP_ID have different names
B. Because the columns EMP.HIRED and EX_EMP.HIRED are different data types
C. Because there are two columns in the first query and three columns in the second query
D. For all the reasons above
E. The query will succeed.
In what order will the rows be returned? (Choose the best answer.)
A. The rows from each table will be grouped and within each group will be sorted on ENAME.
B. The rows from each table will be grouped but not sorted.
C. The rows will not be grouped but will all be sorted on ENAME.
D. The rows will be neither grouped nor sorted.
LAB QUESTION
Working in the HR schema, design some queries that will generate reports using the set operators.
The reports required are as follows:
1. Employees have their current job (identified by JOB_ID) recorded in their EMPLOYEES row.
Jobs they have held previously (but not their current job) are recorded in JOB_HISTORY.
Which employees have never changed jobs? The listing should include the employees
EMPLOYEE_ID and LAST_NAME.
Lab Question 399
2. Which employees were recruited into one job, then changed to a different job, but are now
back in a job they held before? Again, you will need to construct a query that compares
EMPLOYEES with JOB_HISTORY. The report should show the employees names and the job
titles. Job titles are stored in the table JOBS.
3. What jobs has any one employee held? This will be the JOB_ID for the employees current
job (in EMPLOYEES) and all previous jobs (in JOB_HISTORY). If the employee has held a
job more than once, there is no need to list it more than once. Use a replacement variable to
prompt for the EMPLOYEE_ID and display the job title(s). Employees 101 and 200 will be
suitable employees for testing.