Consider the following database tables of a sports league.
player (pid, pname, age) team(tid, tname, city, cid) coach (cid, cname) members (pid,tid)
An instance of the table and an SQL query are given.
SELECT MIN (P.age)
FROM player P
WHERE P.pid IN (
SELECT M.pid
FROM team T, coach C, members M
WHERE C.cname = 'Mark'
AND T.cid = C.cid
AND M.tid = T.tid
)The value returned by the given SQL query is _________. (Answer in integer)
View worked solution
Answer: 26:26
To find the value returned by the given SQL query, we can evaluate it step-by-step starting from the nested subquery.
Step 1: Evaluate the Nested Subquery
The subquery is:
SELECT M.pid
FROM team T, coach C, members M
WHERE C.cname = 'Mark'
AND T.cid = C.cid
AND M.tid = T.tid
- Filter by Coach Name:
From the
coachtable, the row withcname = 'Mark'hascid = 102. - Join with Team Table (
T.cid = C.cid): From theteamtable, the row withcid = 102hastid = 10(team name MI). - Join with Members Table (
M.tid = T.tid): From thememberstable, we find thepidvalues associated withtid = 10:pid = 1(wheretid = 10)pid = 3(wheretid = 10)
Thus, the subquery returns the set of player IDs: {1, 3}.
Step 2: Evaluate the Outer Query
The outer query is:
SELECT MIN (P.age)
FROM player P
WHERE P.pid IN (1, 3)
From the player table, we look up the ages of players with pid in {1, 3}:
- For
pid = 1(Jasprit):age = 31 - For
pid = 3(Ishan):age = 26
Taking the minimum of these ages:
Therefore, the value returned by the SQL query is 26.
Free practice · Your answers on this page are not saved.
