ORACLE DATABASE INTERVIEW QUESTIONS
Explain the typical execution order of a SQL query in Oracle and discuss why understanding this order is crucial for query optimization
Given the following query, in what order will Oracle execute the clauses, and how does it affect the result set? SELECT department_id, COUNT(*) FROM employees WHERE salary > 5000 GROUP BY department_id HAVING COUNT(*) > 5 ORDER BY department_id;
In the following Oracle SQL query, what would happen if you switched the positions of HAVING and WHERE, and why is it important to maintain the correct order? SELECT job_id, AVG(salary) FROM employees WHERE department_id = 10 GROUP BY job_id HAVING AVG(salary) > 6000;
Given the following query, explain how Oracle handles the WHERE, GROUP BY , and HAVING clauses in relation to each other. SELECT department_id, SUM(salary) as total_salary FROM employees WHERE commission_pct IS NOT NULL GROUP BY department_id HAVING SUM(salary) > 50000;
Consider the following Oracle SQL query. How does the order of execution impact the final output, and what would be the effect if the WHERE clause was more complex? SELECT job_id, COUNT(*) FROM employees WHERE salary > 7000 AND department_id IN (10, 20) GROUP BY job_id HAVING COUNT(*) > 3 ORDER BY COUNT(*) DESC;
In Oracle SQL, how does the placement of the ORDER BY clause relative to the GROUP BY and HAVING clauses affect the result of the following query? SELECT department_id, MAX(salary) FROM employees GROUP BY department_id HAVING MAX(salary) > 10000 ORDER BY department_id;
Analyze the following query and explain how Oracle SQL determines which rows are returned. What impact does the execution order have on the result set? SELECT department_id, AVG(salary) FROM employees WHERE job_id = SA_REP GROUP BY department_id HAVING AVG(salary) BETWEEN 6000 AND 8000 ORDER BY AVG(salary) DESC;
What would be the effect of removing the GROUP BY clause in the following Oracle SQL query, and why is the execution order important in this context? SELECT department_id, COUNT(*) FROM employees WHERE job_id = IT_PROG GROUP BY department_id HAVING COUNT(*) > 2 ORDER BY COUNT(*) DESC;
In Oracle SQL, how can you use subqueries within the WHERE and HAVING clauses to further refine the result set, and how does this affect the execution order?
Question:For the following Oracle SQL query, explain how the order of execution affects the performance and what optimizations could be applied. sql SELECT employee_id, department_id, salary FROM employees WHERE department_id IN (SELECT department_id FROM departments WHERE location_id = 1700) AND salary > (SELECT AVG(salary) FROM employees WHERE department_id = 10) ORDER BY salary DESC;
