Oracle Certification

1Z0-071 — Oracle Database SQL Study Guide

61 practice questions with correct answers and detailed explanations. Use this guide to review concepts before taking the practice exam.

▶ Take Practice Exam 61 questions  ·  Free  ·  No registration

About the 1Z0-071 Exam

The Oracle Oracle Database SQL (1Z0-071) certification validates professional expertise in Oracle technologies. This study guide covers all 61 practice questions from our 1Z0-071 practice test, complete with correct answers and explanations to help you understand each concept thoroughly.

Review each question and explanation below, then test yourself with the full interactive practice exam to measure your readiness.

61 Practice Questions & Answers

Q1 Easy

Which clause is used to eliminate duplicate rows from the result set of a query?

  • A GROUP BY
  • B DISTINCT ✓ Correct
  • C HAVING
  • D UNIQUE
Explanation

The DISTINCT keyword removes duplicate rows from query results. UNIQUE is a constraint type, GROUP BY is for aggregation, and HAVING filters grouped data.

Q2 Easy

What is the purpose of the HAVING clause in SQL?

  • A To sort the result set in ascending order
  • B To filter rows before grouping
  • C To join multiple tables together
  • D To filter groups based on aggregate functions ✓ Correct
Explanation

HAVING filters groups after GROUP BY aggregation is performed, typically using aggregate functions like SUM(), COUNT(), or AVG().

Q3 Easy

Which of the following statements about INNER JOIN is correct?

  • A It returns all rows from both tables regardless of whether they match or not
  • B It returns all rows from the left table and matching rows from the right table
  • C It returns only rows where there is a match in both tables being joined ✓ Correct
  • D It combines rows from two tables based on a common column without any filtering
Explanation

INNER JOIN returns only rows that have matching values in both tables based on the join condition. Unmatched rows are excluded.

Q4 Medium

What will be the result of the following query? SELECT employee_id, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);

  • A It will return employees whose salary is greater than the maximum salary in the table
  • B It will produce an error because subqueries cannot be used in WHERE clause
  • C It will return employees whose salary is greater than the average salary ✓ Correct
  • D It will return all employees with their salaries sorted in descending order
Explanation

This query uses a subquery in the WHERE clause to calculate the average salary, then filters employees earning above that average. Subqueries are valid in WHERE clauses.

Q5 Medium

Which join type will return all rows from the left table and matching rows from the right table?

  • A RIGHT OUTER JOIN
  • B FULL OUTER JOIN
  • C INNER JOIN
  • D LEFT OUTER JOIN ✓ Correct
Explanation

LEFT OUTER JOIN returns all rows from the left table plus matching rows from the right table. Non-matching right table rows will have NULL values.

Q6 Medium

What does the UNION operator do when combining results from two SELECT statements?

  • A It returns only rows that appear in both result sets
  • B It combines results and keeps all rows including duplicates
  • C It returns rows from the first SELECT statement that do not appear in the second
  • D It combines results and removes duplicate rows ✓ Correct
Explanation

UNION combines two result sets and automatically removes duplicate rows. UNION ALL keeps all rows including duplicates, INTERSECT returns common rows, and MINUS returns differences.

Q7 Easy

Which aggregate function returns the number of non-NULL values in a column?

  • A MAX()
  • B SUM()
  • C COUNT() ✓ Correct
  • D AVG()
Explanation

COUNT() returns the number of non-NULL values in a specified column. COUNT(*) counts all rows including those with NULL values.

Q8 Easy

What is the result of executing: SELECT ROUND(15.567, 2) FROM dual;

  • A 16
  • B 15.5
  • C 15.57 ✓ Correct
  • D 15.6
Explanation

ROUND(15.567, 2) rounds the number to 2 decimal places, resulting in 15.57.

Q9 Easy

Which SQL function is used to convert a string to uppercase?

  • A UPPERCASE()
  • B UPCASE()
  • C TO_UPPER()
  • D UPPER() ✓ Correct
Explanation

UPPER() is the standard Oracle SQL function to convert strings to uppercase. UPCASE(), TO_UPPER(), and UPPERCASE() are not valid Oracle functions.

Q10 Medium

What is the difference between CHAR and VARCHAR2 data types in Oracle?

  • A There is no practical difference between them in modern Oracle versions
  • B VARCHAR2 can store Unicode characters while CHAR cannot
  • C CHAR is fixed length and VARCHAR2 is variable length, and CHAR pads with spaces ✓ Correct
  • D CHAR is variable length and VARCHAR2 is fixed length
Explanation

CHAR stores fixed-length strings and pads with spaces to reach the specified length, while VARCHAR2 stores variable-length strings without padding.

Q11 Medium

Which of the following queries will return employee names and their corresponding department names?

  • A SELECT e.name FROM employees e UNION SELECT d.name FROM departments d
  • B SELECT e.name FROM employees e WHERE e.dept_id IN (SELECT d.id FROM departments d)
  • C SELECT e.name, d.name FROM employees e, departments d WHERE e.name = d.name
  • D SELECT e.name, d.name FROM employees e JOIN departments d ON e.dept_id = d.id ✓ Correct
Explanation

An INNER JOIN on the department ID column correctly matches employees with their departments. Other options either return only names or produce meaningless results.

Q12 Medium

What will happen if you use COUNT(*) with a GROUP BY clause that produces no matching rows?

  • A The query will return NULL values for non-matching groups
  • B The query will return one row with a count of 0 for each group
  • C The query will return an error
  • D The query will return no rows ✓ Correct
Explanation

If no rows match the GROUP BY criteria, the query returns no rows at all, not zero counts. This is different from a group that exists but has zero matching rows.

Q13 Medium

Which statement about NULL values in Oracle SQL is correct?

  • A NULL is equal to zero or empty string and can be compared using the = operator
  • B NULL represents the absence of a value and must be tested using IS NULL or IS NOT NULL ✓ Correct
  • C NULL values are treated as the smallest value in sorting operations
  • D NULL can be compared using comparison operators like > and < in WHERE clauses
Explanation

NULL represents unknown or missing data and cannot be compared using standard operators. IS NULL and IS NOT NULL operators must be used to test for NULL values.

Q14 Medium

What does the following query return? SELECT department_id, COUNT(*) as emp_count FROM employees GROUP BY department_id HAVING COUNT(*) > 5;

  • A Departments with more than 5 employees ✓ Correct
  • B All departments and their employee counts
  • C The total count of employees in the entire company where the count exceeds 5
  • D All employees grouped by department sorted by count
Explanation

This query groups employees by department and uses HAVING to filter only those groups with more than 5 employees, returning department IDs and their counts.

Q15 Medium

Which function would you use to extract the month from a date column?

  • A MONTH(date_column)
  • B EXTRACT(MONTH FROM date_column) ✓ Correct
  • C GET_MONTH(date_column)
  • D DATE_PART('month', date_column)
Explanation

EXTRACT() is the Oracle SQL function to extract date parts like MONTH, YEAR, or DAY from a date column. MONTH() and DATE_PART() are not standard Oracle functions.

Q16 Medium

What is the correct syntax for a CASE expression that returns values based on conditions?

  • A SELECT CASE WHEN salary > 5000 THEN 'High' ELSE 'Low' END FROM employees; ✓ Correct
  • B SELECT SWITCH(salary > 5000, 'High', 'Low') FROM employees;
  • C SELECT IF(salary > 5000, 'High', 'Low') FROM employees;
  • D SELECT salary CASE 'High' WHEN > 5000 ELSE 'Low' FROM employees;
Explanation

CASE WHEN...THEN...ELSE...END is the correct Oracle syntax for conditional expressions. IF(), SWITCH() and other variations are not valid in Oracle SQL.

Q17 Hard

Which of the following will correctly add 6 months to a date column?

  • A Both A and B are correct ✓ Correct
  • B SELECT hire_date + 180 FROM employees;
  • C SELECT ADD_MONTHS(hire_date, 6) FROM employees;
  • D SELECT hire_date + INTERVAL '6' MONTH FROM employees;
Explanation

Both ADD_MONTHS() and INTERVAL syntax are valid in Oracle SQL for adding months to dates. Adding 180 (days) would be approximate and not accurate.

Q18 Medium

What happens when you use an aggregate function like SUM() without a GROUP BY clause?

  • A The aggregate function is applied to only the first row of the result set
  • B The aggregate function calculates across all rows in the table
  • C The query returns one row with the aggregate value calculated from all matching rows ✓ Correct
  • D The query produces an error because GROUP BY is mandatory with aggregate functions
Explanation

When using an aggregate function without GROUP BY, SQL calculates the aggregate across all rows and returns a single row with that result.

Q19 Medium

Which statement correctly describes the behavior of LEFT OUTER JOIN when there are no matching rows?

  • A Non-matching rows from the left table are included with NULL values for right table columns ✓ Correct
  • B Non-matching rows are returned only if the ON condition uses IS NULL
  • C Non-matching rows from the left table are excluded entirely from the result
  • D The entire join operation fails and produces an error
Explanation

LEFT OUTER JOIN includes all rows from the left table. When there's no match in the right table, the right table columns contain NULL values.

Q20 Medium

What is the correct way to sort results by multiple columns in descending order?

  • A SELECT * FROM employees DESC ORDER BY salary, hire_date;
  • B SELECT * FROM employees ORDER BY salary, hire_date DESC DESC;
  • C SELECT * FROM employees ORDER BY salary DESC, hire_date DESC; ✓ Correct
  • D SELECT * FROM employees ORDER BY DESC salary, DESC hire_date;
Explanation

Each column in ORDER BY clause needs its own sort direction specification. DESC must follow the column name to sort that column in descending order.

Q21 Hard

Which of the following correctly demonstrates the use of a correlated subquery?

  • A SELECT * FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id); ✓ Correct
  • B SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
  • C SELECT * FROM employees WHERE department_id IN (SELECT department_id FROM departments);
  • D SELECT * FROM employees INNER JOIN (SELECT * FROM departments) ON employees.dept_id = departments.id;
Explanation

A correlated subquery references columns from the outer query (e.department_id). This query finds employees earning more than the average in their department.

Q22 Medium

What will the following query return? SELECT * FROM employees WHERE commission_percent IS NOT NULL AND salary > 3000;

  • A All employees whose commission_percent or salary values exist in the database
  • B Employees with NULL commission and salary greater than 3000
  • C Employees with either non-NULL commission or salary greater than 3000
  • D Employees with a non-NULL commission and salary greater than 3000 ✓ Correct
Explanation

The AND operator requires both conditions to be true: commission_percent must have a value (not NULL) AND salary must exceed 3000.

Q23 Easy

Which aggregate function would you use to find the highest salary in the employees table?

  • A HIGHEST(salary)
  • B MAXIMUM(salary)
  • C MAX(salary) ✓ Correct
  • D TOP(salary)
Explanation

MAX() is the standard Oracle SQL aggregate function to find the maximum value in a column. HIGHEST(), MAXIMUM(), and TOP() are not valid aggregate functions.

Q24 Hard

What is the difference between a subquery in the WHERE clause versus a subquery in the FROM clause?

  • A FROM subqueries are always slower than WHERE subqueries
  • B WHERE subqueries can return multiple columns while FROM subqueries can only return one
  • C WHERE subqueries filter rows while FROM subqueries act as a derived table or inline view ✓ Correct
  • D There is no practical difference between them in Oracle SQL
Explanation

WHERE subqueries filter based on conditions, while FROM subqueries (derived tables/inline views) create a temporary result set that the main query can select from.

Q25 Hard

When using GROUP BY, which columns can appear in the SELECT list without being in an aggregate function?

  • A Columns that have unique values across all rows
  • B Any columns from any table in the query
  • C Columns must either be in GROUP BY or wrapped in an aggregate function
  • D Only columns that are referenced in the GROUP BY clause ✓ Correct
Explanation

In GROUP BY queries, non-aggregated columns in SELECT must appear in the GROUP BY clause, otherwise results would be ambiguous or cause an error.

Q26 Medium

What does the INTERSECT operator return when used between two SELECT statements?

  • A Only rows that appear in both result sets ✓ Correct
  • B Rows from the first result set in reverse order compared to the second
  • C All rows from both result sets combined
  • D All rows that appear in the first result set but not in the second
Explanation

INTERSECT returns rows that are common to both queries' result sets. UNION combines all rows, MINUS returns first set minus second, and EXCEPT is a non-standard operator.

Q27 Hard

Which of the following statements about implicit data type conversion in Oracle is most accurate?

  • A Data types never need conversion because Oracle treats all columns as universal string types
  • B Oracle will always automatically convert VARCHAR2 to NUMBER in all comparison operations
  • C Implicit conversions are forbidden in Oracle and will always produce errors
  • D Oracle performs implicit conversions in some situations, but it's best practice to use explicit conversion functions like TO_NUMBER() and TO_CHAR() ✓ Correct
Explanation

While Oracle does perform some implicit conversions, using explicit functions like TO_NUMBER(), TO_CHAR(), and TO_DATE() is considered best practice for clarity and predictability.

Q28 Easy

Which clause is used to filter groups in a GROUP BY query?

  • A HAVING ✓ Correct
  • B GROUP FILTER
  • C WHERE
  • D FILTER
Explanation

HAVING is the correct clause for filtering groups created by GROUP BY, whereas WHERE filters individual rows before grouping.

Q29 Medium

Which of the following is a valid use of the CASE expression in Oracle SQL?

  • A SELECT salary CASE WHEN > 50000 THEN 'High' FROM employees;
  • B SELECT CASE (salary) WHEN > 50000 THEN 'High' END FROM employees;
  • C SELECT CASE WHEN salary > 50000 THEN 'High' ELSE 'Low' END FROM employees; ✓ Correct
  • D SELECT CASE salary > 50000 FROM employees;
Explanation

The correct CASE syntax is CASE WHEN condition THEN result ELSE alternative_result END, as shown in option A.

Q30 Medium

What does the INTERSECT operator return?

  • A All rows from the first query minus rows that appear in the second query
  • B Only the rows that appear in the first query but not the second
  • C Rows that appear in both queries, with duplicates removed ✓ Correct
  • D All rows from both queries combined, with duplicates removed
Explanation

INTERSECT returns only the rows that exist in both result sets, automatically removing duplicates.

Q31 Medium

Which function converts a character string to a number data type?

  • A TO_NUMBER(x)
  • B CAST(x AS NUMBER)
  • C Both A and B are correct ✓ Correct
  • D CONVERT(x, NUMBER)
Explanation

Both CAST and TO_NUMBER can convert character strings to numbers in Oracle; CAST is ANSI standard while TO_NUMBER is Oracle-specific.

Q32 Easy

What is the purpose of the ORDER BY clause?

  • A To eliminate duplicate rows from the result set
  • B To group rows with similar column values
  • C To arrange rows in a specified order based on one or more columns ✓ Correct
  • D To filter rows that meet specific conditions before grouping
Explanation

ORDER BY sorts the result set in ascending (ASC) or descending (DESC) order based on specified columns.

Q33 Medium

Which of the following statements correctly uses the DISTINCT keyword?

  • A SELECT DISTINCT * FROM employees WHERE DISTINCT salary > 50000;
  • B SELECT department_id, DISTINCT salary FROM employees ORDER BY salary;
  • C SELECT DISTINCT department_id, salary FROM employees WHERE salary > 50000 ORDER BY department_id; ✓ Correct
  • D SELECT department_id DISTINCT, salary FROM employees;
Explanation

DISTINCT must appear immediately after SELECT and applies to all columns in the result set; it removes duplicate rows.

Q34 Easy

What does an INNER JOIN return?

  • A All rows from the left table, including those without matches in the right table
  • B All rows from both tables, matching or not
  • C Rows from the right table with corresponding matches from the left table
  • D Only rows where values exist in both tables being joined ✓ Correct
Explanation

INNER JOIN returns only the rows that have matching values in both tables based on the join condition.

Q35 Easy

Which aggregate function returns the number of non-NULL values in a column?

  • A TOTAL()
  • B ROWS()
  • C SUM()
  • D COUNT() ✓ Correct
Explanation

COUNT() counts the number of non-NULL values; COUNT(*) counts all rows including those with NULL values.

Q36 Medium

In a LEFT OUTER JOIN, what happens to rows in the right table that have no match in the left table?

  • A They are included with their original values from the right table
  • B They cause the join to fail with an error
  • C They are excluded from the result set entirely ✓ Correct
  • D They are included in the result set with NULL values for left table columns
Explanation

LEFT OUTER JOIN preserves all rows from the left table; unmatched rows from the right table are excluded and replaced with NULLs only for right table columns where a match occurs.

Q37 Hard

What is the correct syntax for a correlated subquery?

  • A SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
  • B SELECT * FROM (SELECT * FROM employees WHERE salary > 50000) AS e;
  • C SELECT * FROM employees e, (SELECT * FROM departments) d WHERE e.department_id = d.department_id;
  • D SELECT * FROM employees e WHERE salary > (SELECT AVG(salary) FROM employees WHERE department_id = e.department_id); ✓ Correct
Explanation

A correlated subquery references columns from the outer query (in this case, e.department_id), executing once for each outer row.

Q38 Medium

Which function extracts the year from a DATE column?

  • A YEAR_OF(column_name)
  • B EXTRACT(YEAR FROM column_name) ✓ Correct
  • C GETDATE()
  • D DATEPART(YEAR, column_name)
Explanation

EXTRACT is the Oracle SQL function to extract date components; DATEPART is SQL Server syntax.

Q39 Easy

What does the UNION operator do?

  • A Joins two tables based on a condition specified in the ON clause
  • B Combines result sets from multiple queries and removes duplicate rows ✓ Correct
  • C Combines result sets from multiple queries, keeping duplicates
  • D Returns only rows that appear in the first query but not the second
Explanation

UNION combines results from multiple SELECT statements and automatically removes duplicates; use UNION ALL to keep duplicates.

Q40 Hard

When using GROUP BY with aggregate functions, which columns can appear in the SELECT clause without aggregation?

  • A Only columns wrapped in aggregate functions like SUM() or COUNT()
  • B Any column from the base tables
  • C Only columns that appear in the GROUP BY clause, or columns wrapped in aggregate functions ✓ Correct
  • D All columns from all joined tables
Explanation

In a GROUP BY query, non-aggregated columns in SELECT must appear in the GROUP BY clause to avoid ambiguity about which row's value to display.

Q41 Medium

Which of the following correctly uses the LIKE operator with wildcards?

  • A SELECT * FROM employees WHERE last_name LIKE 'S%' to find names starting with S
  • B SELECT * FROM employees WHERE last_name LIKE '%S%' to find names containing S anywhere
  • C SELECT * FROM employees WHERE last_name LIKE 'S_' to find names starting with S followed by exactly one character
  • D All of the above are correct uses of LIKE ✓ Correct
Explanation

All three examples correctly demonstrate LIKE usage: % matches zero or more characters and _ matches exactly one character.

Q42 Easy

What is returned by: SELECT NVL(NULL, 'No value') FROM DUAL;

  • A NULL
  • B 'No value' ✓ Correct
  • C An error message
  • D Empty string
Explanation

NVL returns the second parameter when the first parameter is NULL, so NVL(NULL, 'No value') returns 'No value'.

Q43 Medium

Which JOIN type would you use to display all employees and their corresponding departments, including employees with no department assignment?

  • A FULL OUTER JOIN
  • B RIGHT OUTER JOIN
  • C INNER JOIN
  • D LEFT OUTER JOIN ✓ Correct
Explanation

LEFT OUTER JOIN preserves all rows from the left table (employees) and includes matching rows from the right table (departments), with NULLs for unmatched rows.

Q44 Medium

What is the difference between COUNT(*) and COUNT(column_name)?

  • A COUNT(*) counts distinct rows; COUNT(column_name) counts duplicate rows
  • B There is no difference; both produce identical results
  • C COUNT(*) counts all rows; COUNT(column_name) counts only non-NULL values in that column ✓ Correct
  • D COUNT(*) counts only non-NULL rows; COUNT(column_name) counts all rows including NULL
Explanation

COUNT(*) counts every row in the result set including NULLs, while COUNT(column_name) excludes rows where that column is NULL.

Q45 Medium

Which statement is true about self-joins?

  • A A self-join requires the use of UNION to combine the results from two separate queries
  • B A self-join can only be used with tables that have a parent-child relationship defined by foreign keys
  • C A self-join joins a table to itself, typically using table aliases to distinguish the two instances ✓ Correct
  • D Self-joins cannot be used with aggregate functions like SUM() or COUNT()
Explanation

A self-join joins a single table to itself, requiring aliases (like e1 and e2) to reference the different instances of the same table.

Q46 Hard

What is the correct way to handle NULL values when sorting with ORDER BY?

  • A NULL values automatically appear last in descending order
  • B NULL values cannot be sorted and will cause an error
  • C NULL values automatically appear first in ascending order
  • D Use NULLS FIRST or NULLS LAST to explicitly control NULL placement in the sort order ✓ Correct
Explanation

Oracle SQL allows NULLS FIRST and NULLS LAST clauses in ORDER BY to explicitly position NULL values in the result set.

Q47 Medium

Which of the following is the correct use of an IN operator with a subquery?

  • A SELECT * FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 100); ✓ Correct
  • B SELECT * FROM employees WHERE department_id = IN (SELECT department_id FROM departments WHERE location_id = 100);
  • C SELECT * FROM employees WHERE department_id IN SELECT department_id FROM departments WHERE location_id = 100;
  • D SELECT * FROM employees WHERE IN department_id (SELECT department_id FROM departments WHERE location_id = 100);
Explanation

The correct syntax is column_name IN (subquery), where the subquery must be enclosed in parentheses.

Q48 Medium

What does the CROSS JOIN produce?

  • A All rows from the first table with NULL values for columns from the second table
  • B Only rows that have matching values in both tables
  • C A Cartesian product of two tables, combining every row from the first table with every row from the second table ✓ Correct
  • D A result set that contains only the unique values from both tables
Explanation

A CROSS JOIN (or Cartesian join) returns all possible combinations of rows, with each row from table1 paired with every row from table2.

Q49 Medium

Which function would you use to remove leading and trailing spaces from a character string?

  • A LTRIM() removes only leading spaces; RTRIM() removes only trailing spaces
  • B SUBSTR() can be used to remove spaces from character strings
  • C Both A and B are correct ways to handle space removal ✓ Correct
  • D TRIM() removes both leading and trailing spaces
Explanation

TRIM removes both leading/trailing spaces by default; LTRIM and RTRIM handle leading/trailing spaces individually; all are valid approaches.

Q50 Hard

In the expression SELECT salary, AVG(salary) FROM employees, why will this fail?

  • A AVG() cannot be used with numeric columns containing NULL values
  • B When using aggregate functions without GROUP BY, all non-aggregated columns in SELECT must also be aggregated ✓ Correct
  • C The AVG function requires two arguments to calculate the average between two salary ranges
  • D The salary column must be wrapped in an aggregate function like MAX() or MIN()
Explanation

Without a GROUP BY clause, all columns in SELECT must be aggregate functions or constants; salary must be aggregated to avoid ambiguity.

Q51 Hard

Which of the following statements about HAVING is correct?

  • A HAVING must appear before the GROUP BY clause in the query
  • B HAVING is used to filter rows before grouping, similar to WHERE
  • C HAVING filters groups created by GROUP BY and can reference aggregate functions in its conditions ✓ Correct
  • D HAVING can reference any column from the base table, aggregated or not
Explanation

HAVING filters groups after GROUP BY is applied and can use aggregate functions; it appears after GROUP BY in the query structure.

Q52 Easy

Which clause is used to eliminate duplicate rows from the result set of a query?

  • A DISTINCT ✓ Correct
  • B GROUP BY
  • C REMOVE DUPLICATES
  • D UNIQUE
Explanation

The DISTINCT keyword removes duplicate rows from query results. UNIQUE is a constraint type, not a clause, and REMOVE DUPLICATES is not valid SQL syntax.

Q53 Medium

You need to retrieve employee names and their department names using a join. Employee records may not have corresponding department records. Which join type should you use?

  • A LEFT OUTER JOIN ✓ Correct
  • B INNER JOIN
  • C CROSS JOIN
  • D RIGHT OUTER JOIN
Explanation

LEFT OUTER JOIN returns all rows from the left table (employees) even if they have no matching records in the right table (departments). INNER JOIN would exclude employees without departments, while RIGHT OUTER JOIN would give the opposite result.

Q54 Medium

What is the primary purpose of the HAVING clause in SQL?

  • A To establish relationships between multiple tables
  • B To filter individual rows before grouping occurs
  • C To filter groups after the GROUP BY operation is performed ✓ Correct
  • D To define which columns appear in the SELECT list
Explanation

HAVING filters grouped data after GROUP BY is applied, whereas WHERE filters individual rows before grouping. This distinction is critical for understanding aggregate functions and group filtering.

Q55 Medium

You execute the following query: SELECT department_id, COUNT(*) FROM employees GROUP BY department_id HAVING COUNT(*) > 5; What does this query return?

  • A The first 5 employees from each department
  • B All employees grouped by department in the first 5 rows
  • C Departments and their employee counts where the count exceeds 5 ✓ Correct
  • D All departments with exactly 5 employees
Explanation

The HAVING clause filters groups to include only those where COUNT(*) is greater than 5, returning department IDs and their employee counts meeting this condition. The HAVING clause operates on aggregated data, not individual rows.

Q56 Medium

Which statement about subqueries is correct?

  • A Subqueries can be used in WHERE, FROM, and SELECT clauses ✓ Correct
  • B Subqueries must always use the IN operator to be valid
  • C Subqueries cannot reference columns from the outer query
  • D Subqueries can only return a single row of data
Explanation

Subqueries are flexible and can appear in multiple clauses (WHERE, FROM, SELECT, HAVING). They can return single or multiple rows and may use various operators depending on context.

Q57 Hard

You want to find the employee with the maximum salary in each department. Which approach would be most efficient?

  • A Use a correlated subquery in the WHERE clause to compare each row's salary with the department maximum
  • B Use the RANK() window function with PARTITION BY department_id ✓ Correct
  • C Create a temporary table, then join it with the employees table
  • D Use a self-join between the employees table and a grouped result set
Explanation

Window functions like RANK() with PARTITION BY are optimized for this type of analysis and provide better performance than correlated subqueries or self-joins on large datasets.

Q58 Medium

What is the difference between UNION and UNION ALL in Oracle SQL?

  • A UNION ALL is faster because it performs additional sorting operations
  • B UNION can combine more than two result sets while UNION ALL can only combine two
  • C UNION removes duplicates while UNION ALL retains all rows including duplicates ✓ Correct
  • D UNION is used for vertical combinations while UNION ALL is used for horizontal combinations
Explanation

UNION eliminates duplicate rows from the combined result set, while UNION ALL includes all rows. UNION ALL is typically faster because it avoids the overhead of removing duplicates.

Q59 Medium

Consider this query: SELECT employee_id, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees); What does this return?

  • A A list of departments with average salaries greater than the company overall average
  • B All employees and their salaries, ordered by those above average
  • C The count of employees earning more than the company average, grouped by department
  • D Employees whose individual salary exceeds the overall average salary of all employees ✓ Correct
Explanation

This query uses a scalar subquery to calculate the company-wide average salary, then returns employee_id and salary for those individuals whose salary exceeds that average. It does not perform any grouping.

Q60 Hard

Which of the following correctly describes the behavior of the CASE expression in Oracle SQL?

  • A CASE expressions support both simple and searched syntax, allowing conditional logic in SELECT, WHERE, and ORDER BY clauses ✓ Correct
  • B CASE expressions cannot reference aggregate functions like SUM or COUNT
  • C CASE expressions must include an ELSE clause; omitting it will cause an error
  • D CASE expressions can only be used with numeric data types
Explanation

CASE expressions are versatile and support both simple CASE (comparing one value) and searched CASE (multiple conditions) formats. They work with any data type and can appear in various clauses. The ELSE clause is optional; if omitted, unmatched values return NULL.

Q61 Easy

You need to concatenate first_name and last_name columns with a space between them. In Oracle SQL, which is the preferred modern approach?

  • A SELECT first_name + ' ' + last_name FROM employees;
  • B SELECT first_name || ' ' || last_name FROM employees; ✓ Correct
  • C SELECT CONCATENATE(first_name, ' ', last_name) FROM employees;
  • D SELECT CONCAT(first_name, last_name) FROM employees;
Explanation

The concatenation operator (||) is the standard Oracle SQL approach and handles multiple values elegantly. CONCAT() exists but is more commonly associated with MySQL; it also only handles two arguments natively. The + operator is not valid for string concatenation in Oracle SQL.

Ready to test your knowledge?

You've reviewed all 61 questions. Take the interactive practice exam to simulate the real test environment.

▶ Start Practice Exam — Free