GateAI
SQL

GATE CSE 2014 Set 1 · Q54

MCQ2 marksMedium

Time

Given the following schema:employees(emp-id, first-name, last-name, hire-date, dept-id, salary)departments(dept-id, dept-name, manager-id, location-id) 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 (dept-id, hire-date) IN (SELECT dept-id, MAX(hire-date) FROM employees JOIN departments USING(dept-id) WHERE location-id = 1700 GROUP BY dept-id);What is the outcome?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) It executes and gives the correct result.

SQL
  1. The subquery performs an inner join between employees and departments using dept-id, and filters the records for location-id = 1700.

  2. It groups the results by dept-id and finds the latest hire date (MAX(hire-date)) for each department at location 1700.

  3. The subquery returns pairs of (dept-id, MAX(hire-date)).

  4. Standard SQL supports pairwise (multi-column) tuple comparisons using the IN clause with a subquery.

  5. The outer query matches (dept-id, hire-date) against these pairs, correctly returning the last-name and hire-date of all employees who are the latest hires in their respective departments located at location ID 1700.

Therefore, the query executes and gives the correct result (Option B).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This SQL previous year question is Q54 of the GATE CSE 2014 Set 1 paper. Find more GATE CSE PYQs on SQL in Databases, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related SQL PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

SQL in GATE CSE

SQL has 17 GATE CSE PYQs across 14 papers from 2011 to 2025. 5 of them are 2-mark MCQs like this one, and GATE CSE 2014 Set 1 has 2.

How GATE tests SQL

More from GATE CSE 2014 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 1 · Q54 · MCQ

Given the following schema: employees(emp-id, first-name, last-name, hire-date, dept-id, salary) departments(dept-id, dept-name, manager-id, location-id) 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 (dept-id, hire-date) IN (SELECT dept-id, MAX(hire-date) FROM employees JOIN departments USING(dept-id) WHERE location-id = 1700 GROUP BY dept-id); What is the outcome?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.