Q1
True / FalseIn Oracle, a subquery is a query nested inside another query.
A subquery, also known as an inner query, is a query embedded within another SQL statement.
Q2
True / FalseIn Oracle, a subquery can be used in the SELECT clause to return a single value.
A subquery in the SELECT clause is often used to return a single value, such as an aggregated result.
Q3
True / FalseIn Oracle, subqueries can only be used in the WHERE clause.
Subqueries can be used in various parts of an SQL statement, including the SELECT, FROM, WHERE, HAVING, and ORDER BY clauses.
Q4
True / FalseIn Oracle, subqueries can return multiple rows.
Subqueries can return multiple rows, especially when used with the IN or EXISTS operators.
Q5
True / FalseIn Oracle, a correlated subquery is executed once for each row processed by the outer query.
A correlated subquery refers to columns from the outer query and is evaluated once for each row processed by the outer query.
Q6
True / FalseIn Oracle, subqueries can be used to update records in a table.
Subqueries can be used in UPDATE statements to specify the new values based on a query.
Q7
True / FalseIn Oracle, subqueries can be used in the FROM clause to create a derived table.
Subqueries in the FROM clause are known as derived tables or inline views and can be treated as tables within the main query.
Q8
True / FalseIn Oracle, the ANY and ALL operators can be used with subqueries to compare a value to a set of values returned by the subquery.
The ANY and ALL operators allow comparisons between a single value and a set of values returned by a subquery.
Q9
True / FalseIn Oracle, a subquery cannot be used in a JOIN condition.
Subqueries can be used in JOIN conditions to further refine the join criteria.
Q10
True / FalseThe Oracle Certified Professional (OCP) exam includes knowledge on using subqueries effectively, understanding correlated subqueries, and optimizing subquery performance in complex SQL queries.
The OCP certification covers advanced topics, including the effective use of subqueries, understanding correlated subqueries, and optimizing their performance in complex SQL queries.
Q18
Single ChoiceConsider the following ORACLE SQL query:What does this query do?
SQL Code
SELECT department_name, MAX(salary)
FROM (SELECT department_id, salary FROM employees WHERE department_id IN (10, 20, 30))
GROUP BY department_id;
The subquery filters for departments 10, 20, and 30, and the outer query calculates the maximum salary within each of these departments.
Q21
Multiple ChoiceWhich SQL code snippet demonstrates the use of a subquery to retrieve the highest salary in each department in Oracle?
SQL Code
SELECT department_id, employee_id, salary
FROM employees
WHERE salary = (SELECT MAX(salary)
FROM employees e
WHERE e.department_id = employees.department_id);
SELECT department_id, employee_id, salary
FROM employees
WHERE salary = (SELECT MAX(salary)
FROM employees e
WHERE e.department_id = employees.department_id);
SELECT department_id, employee_id, salary
FROM employees
WHERE salary = (SELECT MAX(salary)
FROM employees e
WHERE e.department_id = employees.department_id);
Options A, B, and C correctly demonstrate the use of a subquery to retrieve the highest salary in each department. Option D is incorrect because it does not use a subquery.
Q22
Multiple ChoiceWhich SQL code snippet demonstrates the use of a subquery to find all employees who earn more than the average salary in their department in Oracle?
SQL Code
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees e
WHERE e.department_id = employees.department_id);
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees e
WHERE e.department_id = employees.department_id);
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees e
WHERE e.department_id = employees.department_id);
Options A, B, and C correctly use a subquery to find all employees who earn more than the average salary in their department. Option D is incorrect because it does not use a subquery.
Q23
Multiple ChoiceWhich SQL code snippet demonstrates the use of a correlated subquery to retrieve employees with the same job title as their manager in Oracle?
SQL Code
SELECT employee_id, first_name, job_id
FROM employees
WHERE job_id = (SELECT job_id
FROM employees e
WHERE e.employee_id = employees.manager_id);
SELECT employee_id, first_name, job_id
FROM employees
WHERE job_id = (SELECT job_id
FROM employees e
WHERE e.employee_id = employees.manager_id);
SELECT employee_id, first_name, job_id
FROM employees
WHERE job_id = (SELECT job_id
FROM employees e
WHERE e.employee_id = employees.manager_id);
Options A, B, and C correctly use a correlated subquery to retrieve employees with the same job title as their manager. Option D is incorrect because it does not use a correlated subquery.
Q26
Multiple ChoiceWhich SQL code snippet demonstrates advanced use of a subquery in the SELECT clause to display the average salary of each department along with each employee's details in Oracle?
SQL Code
SELECT employee_id, first_name, department_id, salary,
(SELECT AVG(salary)
FROM employees e
WHERE e.department_id = employees.department_id) AS avg_salary
FROM employees;
SELECT employee_id, first_name, department_id, salary,
(SELECT AVG(salary)
FROM employees e
WHERE e.department_id = employees.department_id) AS avg_salary
FROM employees;
SELECT employee_id, first_name, department_id, salary,
(SELECT AVG(salary)
FROM employees e
WHERE e.department_id = employees.department_id) AS avg_salary
FROM employees;
Options A, B, and C correctly demonstrate advanced use of a subquery in the SELECT clause to display the average salary of each department along with each employee's details. Option D is incorrect because it does not use a subquery.
Q27
Multiple ChoiceWhich SQL code snippet demonstrates advanced use of a subquery to retrieve employees who earn more than the company average salary in Oracle?
SQL Code
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);
Options A, B, and C correctly demonstrate advanced use of a subquery to retrieve employees who earn more than the company average salary. Option D is incorrect because it does not use a subquery.
Q28
Multiple ChoiceWhich SQL code snippet demonstrates certification-level use of a correlated subquery to find the top earning employee in each department in Oracle?
SQL Code
SELECT department_id, employee_id, salary
FROM employees e1
WHERE salary = (SELECT MAX(salary)
FROM employees e2
WHERE e2.department_id = e1.department_id);
SELECT department_id, employee_id, salary
FROM employees e1
WHERE salary = (SELECT MAX(salary)
FROM employees e2
WHERE e2.department_id = e1.department_id);
SELECT department_id, employee_id, salary
FROM employees e1
WHERE salary = (SELECT MAX(salary)
FROM employees e2
WHERE e2.department_id = e1.department_id);
Options A, B, and C correctly demonstrate certification-level use of a correlated subquery to find the top earning employee in each department. Option D is incorrect because it does not use a correlated subquery.
Q30
Multiple ChoiceWhich SQL code snippet demonstrates certification-level use of a subquery to generate a list of employees who are earning above the average salary across the entire company in Oracle?
SQL Code
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);
SELECT employee_id, first_name, salary
FROM employees
WHERE salary > (SELECT AVG(salary)
FROM employees);
Options A, B, and C correctly demonstrate certification-level use of a subquery to generate a list of employees who are earning above the average salary across the entire company. Option D is incorrect because it does not use a subquery.