Consider the following database tables of a sports league and an SQL query. The value returned by the given SQL query is ______. (Answer in integer)
player
pid
pname
age
1
Jasprit
31
2
Atharva
24
3
Ishan
26
4
Axar
30
coach
cid
cname
101
Ricky
102
Mark
103
Trevor
team
tid
tname
city
cid
10
MI
Mumbai
102
20
DC
Delhi
101
30
PK
Mohali
103
members
pid
tid
1
10
2
30
3
10
4
20
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
)
✅ Final Answer:
The correct answer is 26.
🔹 Short Answer:
The query finds the minimum age of players coached by 'Mark'. First, the inner query finds Mark's coach ID (102), then his team ID (10), and finally the player IDs on that team (1 and 3). The outer query then filters the player table for these IDs, finds their ages (31 and 26), and returns the minimum, which is 26.
🔸 Long Answer:
To solve this, we must evaluate the nested SQL query. The execution starts from the innermost query and works its way out.
Step 1: Evaluate the Inner Subquery
The inner query 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
Let's break down the `WHERE` clause conditions:
C.cname = 'Mark': We filter the `coach` table to find the entry for Mark. This gives us the row `(102, 'Mark')`. So, `C.cid = 102`.
T.cid = C.cid: Now, we join this result with the `team` table where `T.cid = 102`. In the `team` table, the row `(10, 'MI', 'Mumbai', 102)` matches this condition. So, `T.tid = 10`.
M.tid = T.tid: Finally, we join this with the `members` table where `M.tid = 10`. Two rows in the `members` table match: `(1, 10)` and `(3, 10)`.
The `SELECT M.pid` clause then extracts the `pid` values from these resulting rows.
Result of the inner query: The set of player IDs is `{1, 3}`.
Step 2: Evaluate the Outer Query
The outer query now becomes:
SELECT MIN(P.age)
FROM player P
WHERE P.pid IN {1, 3}
FROM player P: We look at the `player` table.
WHERE P.pid IN {1, 3}: We filter this table to find rows where `pid` is either 1 or 3.
Row for pid=1: `(1, Jasprit, 31)`
Row for pid=3: `(3, Ishan, 26)`
SELECT MIN(P.age): From the filtered rows, we take the ages (31 and 26) and find the minimum value.
The minimum of {31, 26} is 26.
Conclusion
The final value returned by the SQL query is 26.
Bibliography:
- Silberschatz, A., Korth, H. F., & Sudarshan, S. (2010). Database System Concepts. McGraw-Hill. (Chapter on SQL).
- Elmasri, R., & Navathe, S. B. (2015). Fundamentals of Database Systems. Pearson.
Ask your doubts in comment form our GURUJEE will reply ASAP, click notify me button so that you get notified on reply.
Get link
Facebook
X
Pinterest
Email
Other Apps
Comments
Popular posts from this blog
GATE 2025 CS/IT Question 1 GATE2025_CS1_Q1 Question: Ravi had ____ younger brother who taught at ____ university. He was widely regarded as ____ honorable man. Select the option with the correct sequence of articles to fill in the blanks. A. a; a; an B. the; an; a C. a; an; a D. an; an; a 👁️ View Full Answer ✅ Final Answer: The correct sequence of articles is (a; a; an) , which corresponds to option (A) . 🔹 Short Answer: The selection of the indefinite article ('a' or 'an') is based on the initial sound of the word that follows. 'a' is used before consonant sounds, and 'an' is used before vowel sounds. 1. " a younger brother" - 'younger' starts with a consonant sound (/j/). 2. " a university" - 'university' starts with a consonant sound (/juː/). 3. " an honorable man"...
GATE 2025 CS/IT Question 64 GATE2025_CS1_Q64 The maximum value of x such that the edge between the nodes B and C is included in every minimum spanning tree of the given graph is ______. (answer in integer) Check Answer 👁️ View Full Answer ✅ Final Answer: The correct answer is 5 . 🔹 Short Answer: For edge (B,C) to be in *every* MST, its weight 'x' must be strictly less than the bottleneck (heaviest edge) of any alternative path between B and C. The alternative paths and their bottlenecks are: B-A-C (bottleneck 7), B-D-C (bottleneck 8), and B-D-A-C (bottleneck 6). To satisfy all conditions, 'x' must be less than the minimum of these bottlenecks, so `x 🔸 Long Answer: Graph for MST Question A B C D 7 6 x ...
GATE 2025 CS/IT Question 65 GATE2025_CS1_Q65 In a double hashing scheme, h₁(k) = k mod 11 and h₂(k) = 1 + (k mod 7) are the auxiliary hash functions. The size m of the hash table is 11. The hash function for the i-th probe in the open address table is [h₁(k) + i h₂(k)] mod m. The following keys are inserted in the given order: 63, 50, 25, 79, 67, 24. The slot at which key 24 gets stored is ______. (Answer in integer) Check Answer 👁️ View Full Answer ✅ Final Answer: The correct answer is 10 . 🔹 Short Answer: To find the slot for key 24, we calculate its hash values: h₁(24) = 24 mod 11 = 2 and h₂(24) = 1 + (24 mod 7) = 1 + 3 = 4. We then probe the hash table. Probe 0: `(2 + 0*4) mod 11 = 2` (collision). Probe 1: `(2 + 1*4) mod 11 = 6` (collision). Probe 2: `(2 + 2*4) mod 11 = 10` (empty). Key 24 is placed in slot 10. 🔸 Long Answer: This problem requi...
Comments
Post a Comment
Ask you doubt here