Oracle Database Quiz Questions

Course Name:Oracle
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:UNION and UNION ALL
Current Quiz Count:30
Progress
0%
Q1
True / False

In Oracle, the UNION operator combines the results of two or more SELECT statements into a single result set, removing duplicates.

Q2
True / False

In Oracle, the UNION ALL operator combines the results of two or more SELECT statements into a single result set, including duplicates.

Q3
True / False

In Oracle, the UNION operator can be used with SELECT statements that have different numbers of columns.

Q4
True / False

The UNION operator in Oracle sorts the combined result set by default.

Q5
True / False

In Oracle, the UNION ALL operator is generally faster than the UNION operator.

Q6
True / False

In Oracle, you can use the ORDER BY clause at the end of a UNION or UNION ALL statement to sort the entire result set.

Q7
True / False

In Oracle, the UNION and UNION ALL operators can be used with complex queries involving JOIN, GROUP BY, and HAVING clauses.

Q8
True / False

In Oracle, you can use the UNION operator to combine results from different tables with different column names.

Q9
True / False

Using the UNION operator in Oracle can lead to performance issues with very large datasets due to the sorting and deduplication process.

Q10
True / False

The Oracle Certified Professional (OCP) exam includes knowledge on using the UNION and UNION ALL operators effectively, optimizing their performance, and understanding their differences and use cases.

Q11
Single Choice

What is the primary difference between UNION and UNION ALL in ORACLE SQL?

Q12
Single Choice

Which of the following ORACLE SQL statements correctly uses UNION to combine two queries?

Q13
Single Choice

In ORACLE SQL, what must be true about the SELECT statements used in a UNION operation?

Q14
Single Choice

Given the following ORACLE SQL queries:What will this query return?

SQL Code
SELECT employee_id FROM employees WHERE department_id = 10
UNION
SELECT employee_id FROM employees WHERE department_id = 20;
Q15
Single Choice

Consider the following Oracle SQL query:What does this query return?

SQL Code
SELECT department_id, COUNT(*) FROM employees GROUP BY department_id
UNION ALL
SELECT department_id, COUNT(*) FROM managers GROUP BY department_id;
Q16
Single Choice

Which of the following is true about the performance of UNION versus UNION ALL in ORACLE SQL?

Q17
Single Choice

What will happen if you use UNION to combine SELECT statements with different numbers of columns in ORACLE SQL?

Q18
Single Choice

Consider the following Oracle SQL query:What does this query return?

SQL Code
SELECT department_name FROM departments
UNION
SELECT department_name FROM projects
ORDER BY department_name;
Q19
Single Choice

Which of the following ORACLE SQL queries would correctly use UNION ALL to combine two tables with different data types in corresponding columns?

Q20
Single Choice

Given the following ORACLE SQL query:What will this query return?

SQL Code
SELECT employee_id FROM employees WHERE salary > 100000
UNION ALL
SELECT employee_id FROM managers WHERE bonus > 20000
INTERSECT
SELECT employee_id FROM employees WHERE hire_date > '2020-01-01';
Q21
Multiple Choice

Which SQL code snippet demonstrates the use of UNION to combine the results of two SELECT queries with no duplicate rows in Oracle?

SQL Code
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 10
UNION
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 20;

SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 10
UNION
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 20
ORDER BY last_name;

SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 10
UNION
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 20;
Q22
Multiple Choice

Which SQL code snippet uses UNION ALL to combine the results of two SELECT queries with all rows, including duplicates, in Oracle?

SQL Code
SELECT product_id, product_name FROM products WHERE category_id = 5
UNION ALL
SELECT product_id, product_name FROM products WHERE category_id = 7;

SELECT product_id, product_name FROM products WHERE category_id = 5
UNION ALL
SELECT product_id, product_name FROM products WHERE category_id = 7
ORDER BY product_name;

SELECT product_id, product_name FROM products WHERE category_id = 5
UNION ALL
SELECT product_id, product_name FROM products WHERE category_id = 7;
Q23
Multiple Choice

Which SQL code snippet demonstrates the use of UNION to retrieve a list of all unique department names and job titles in Oracle?

SQL Code
SELECT department_name FROM departments
UNION
SELECT job_title FROM jobs;

SELECT department_name FROM departments
UNION
SELECT job_title FROM jobs
ORDER BY department_name;

SELECT department_name FROM departments
UNION
SELECT job_title FROM jobs
ORDER BY job_title;
Q24
Multiple Choice

Which SQL code snippet demonstrates the use of UNION ALL to retrieve all employees and their corresponding department names, including duplicates, in Oracle?

SQL Code
SELECT employee_id, department_name FROM employees e
JOIN departments d ON e.department_id = d.department_id
UNION ALL
SELECT employee_id, department_name FROM employees e
JOIN departments d ON e.department_id = d.department_id;

SELECT employee_id, department_name FROM employees e
JOIN departments d ON e.department_id = d.department_id
UNION ALL
SELECT employee_id, department_name FROM employees e
JOIN departments d ON e.department_id = d.department_id
ORDER BY department_name;
Q25
Multiple Choice

Which SQL code snippet demonstrates the use of UNION to combine the results of two queries that retrieve employees with the highest salaries in different departments in Oracle?

SQL Code
SELECT employee_id, first_name, last_name, salary FROM employees WHERE department_id = 10 AND salary = (SELECT MAX(salary) FROM employees WHERE department_id = 10)
UNION
SELECT employee_id, first_name, last_name, salary FROM employees WHERE department_id = 20 AND salary = (SELECT MAX(salary) FROM employees WHERE department_id = 20);

SELECT employee_id, first_name, last_name, salary FROM employees WHERE department_id = 10 AND salary = (SELECT MAX(salary) FROM employees WHERE department_id = 10)
UNION
SELECT employee_id, first_name, last_name, salary FROM employees WHERE department_id = 20 AND salary = (SELECT MAX(salary) FROM employees WHERE department_id = 20)
ORDER BY salary DESC;
Q26
Multiple Choice

Which SQL code snippet demonstrates advanced use of UNION ALL to combine the results of three SELECT queries with all rows, including duplicates, in Oracle?

SQL Code
SELECT employee_id, first_name FROM employees WHERE department_id = 30
UNION ALL
SELECT employee_id, first_name FROM employees WHERE department_id = 40
UNION ALL
SELECT employee_id, first_name FROM employees WHERE department_id = 50;

SELECT employee_id, first_name FROM employees WHERE department_id = 30
UNION ALL
SELECT employee_id, first_name FROM employees WHERE department_id = 40
UNION ALL
SELECT employee_id, first_name FROM employees WHERE department_id = 50
ORDER BY first_name;
Q27
Multiple Choice

Which SQL code snippet demonstrates the use of UNION to retrieve a list of all unique product names from two different tables in Oracle?

SQL Code
SELECT product_name FROM products_a
UNION
SELECT product_name FROM products_b;

SELECT product_name FROM products_a
UNION
SELECT product_name FROM products_b
ORDER BY product_name;

SELECT product_name FROM products_a
UNION
SELECT product_name FROM products_b
ORDER BY product_name;
Q28
Multiple Choice

Which SQL code snippet demonstrates the use of UNION ALL to generate a report that includes all sales data from two different sales tables, including duplicate records, in Oracle?

SQL Code
SELECT sale_id, sale_amount FROM sales_q1
UNION ALL
SELECT sale_id, sale_amount FROM sales_q2;

SELECT sale_id, sale_amount FROM sales_q1
UNION ALL
SELECT sale_id, sale_amount FROM sales_q2
ORDER BY sale_id;

SELECT sale_id, sale_amount FROM sales_q1
UNION ALL
SELECT sale_id, sale_amount FROM sales_q2;
Q29
Multiple Choice

Which SQL code snippet demonstrates certification-level use of UNION to retrieve a comprehensive list of all employees and their managers, ensuring that there are no duplicate rows, in Oracle?

SQL Code
SELECT employee_id, manager_id FROM employees WHERE department_id = 10
UNION
SELECT employee_id, manager_id FROM employees WHERE department_id = 20;

SELECT employee_id, manager_id FROM employees WHERE department_id = 10
UNION
SELECT employee_id, manager_id FROM employees WHERE department_id = 20
ORDER BY manager_id;

SELECT employee_id, manager_id FROM employees WHERE department_id = 10
UNION
SELECT employee_id, manager_id FROM employees WHERE department_id = 20;
Q30
Multiple Choice

Which SQL code snippet demonstrates certification-level use of UNION ALL to create a detailed report combining employee data from three different departments, including all rows, in Oracle?

SQL Code
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 30
UNION ALL
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 40
UNION ALL
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 50;

SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 30
UNION ALL
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 40
UNION ALL
SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 50
ORDER BY last_name;