Question 1
Which window function assigns a unique sequential number to each row, even when there are ties in the ranking column?
- ROW_NUMBER()
- RANK()
- DENSE_RANK()
- ROW_NAMBER()
- RANK_NUM()
Question 2
If you want to find the second highest salary in an employees table, which SQL command would you use?
- SELECT MAX(salary) FROM employees WHERE salary u003C (SELECT MAX(salary) FROM employees);
- SELECT MIN(salary) FROM employees;
- SELECT salary FROM employees WHERE ROWNUM = 2;
- SELECT AVG(salary) FROM employees;
- SELECT salary FROM employees WHERE salary = SECOND_MAX(salary);
Question 3
What is a Common Table Expression (CTE) most commonly used for in SQL?
- To define a temporary result set to simplify complex queries
- To create a new permanent table in the database
- To enforce referential integrity constraints
- To update multiple rows at once using a loop
- To create indexes on specific columns
Question 4
Given a table with duplicate records, what query deletes duplicates but keeps the row with the lowest id?
- DELETE FROM employees WHERE id NOT IN (SELECT MIN(id) FROM employees GROUP BY name, department_id, salary);
- DELETE FROM employees WHERE name IN (SELECT name FROM employees GROUP BY name HAVING COUNT(*) u003E 1);
- DELETE FROM employees WHERE id IN (SELECT id FROM employees GROUP BY name HAVING COUNT(*) = 1);
- DELETE employees WHERE id = MIN(id);
- DELETE FROM employees GROUP BY name, department_id, salary;
Question 5
Which description best defines an SQL window function?
- Performs a calculation across a set of rows related to the current row
- Checks if a value exists within a list of values
- Joins two or more tables based on a related column
- Completely removes a table from the database
- Encrypts column values for security
Question 6
When pivoting data in SQL to count males and females per department, which technique is commonly used?
- CASE WHEN statements inside aggregate functions
- LEFT OUTER JOIN statements only
- UNION ALL without any conditionals
- COALESCE with NULL values
- ORDER BY with multiple columns
Question 7
Which type of SQL join will include all rows from the left table and matching rows from the right table, filling NULLs for non-matches?
- LEFT JOIN
- RIGHT JOIN
- INNER JOIN
- FULL JOIN
- LEF JOIN
Question 8
In SQL, which clause checks efficiently if a subquery returns any rows and is preferred in correlated subqueries for large datasets?
- EXISTS
- IN
- WHERE
- JOIN
- EXIST
Question 9
What is the main purpose of a recursive CTE in SQL?
- To query hierarchical data like organizational charts
- To remove all records from a table
- To permanently store a summarized view
- To force a query to use an index
- To encrypt data within a table
Question 10
Which of the following is a recommended step to optimize a slow SQL query?
- Use indexes on columns used in filters or joins
- Select all columns with SELECT *
- Avoid using any subqueries in all cases
- Create a backup of the table before every SELECT
- Always delete duplicate records before each query