View the Exhibit and examine the structure of the EMPLOYEES and DEPARTMENTS tables. You want to display the last names and hire dates of all latest hires in their respective departments in the location ID 1700. You issue the following query:
SQL>SELECT last_name, hire_date
FROM employees
WHERE (department_id, hire_date) IN
(SELECT department_id, MAX(hire_date)
FROM employees JOIN departments
USING(department_id)
WHERE location_id = 1700
GROUP BY department_id);
What is the outcome?
A. It executes but does not give the correct result
B. It executes successfully and gives the correct result
C. It generates an error because of the pairwise comparison
D. It generates an error because the GROUP BY clause cannot be used with table joins in a subquery
Exhibit:
EMPLOYEES table:
Theory:
Since the query from the question is a SELECT statement with IN condition and a subquery, which uses INNER JOIN that uses USING keyword, so the here is what you need to know to answer that question - SELECT, SUBQUERY, IN CONDITION and JOINS.
Answers:
A - Wrong - the query is correct and does give the correct results as it displays all employees that were hired last within the department with the location id =1700
B - Correct
C - Wrong - pairwise comparison is correct
D - Wrong - a subquery can be any valid SELECT query with any JOIN and GROUP BY clause
0 comments: