Project ForgeSign up free
Database Management Systems
SQL & Transactions
GATE 2015
Medium

Consider the following relations:

Student(Roll_No, Student_Name): (1,Raj), (2,Rohit), (3,Raj) Performance(Roll_No, Course, Marks): (1,Math,80), (1,English,70), (2,Math,75), (3,English,80), (2,Physics,65), (3,Math,80)

Consider the SQL query:

SELECT S.Student_Name, sum(P.Marks) FROM Student S, Performance P WHERE S.Roll_No = P.Roll_No GROUP BY S.Student_Name

The number of rows that will be returned by the SQL query is

  • A1
  • 2
  • C3
  • D6

Explanation

Joining Student and Performance on Roll_No gives 6 rows (one per Performance record, each matched to its student's name): Raj (roll 1, twice), Rohit (roll 2, twice), Raj (roll 3, twice). GROUP BY Student_Name collapses these into distinct NAME groups — not distinct roll numbers — so the two 'Raj' students (roll 1 and roll 3) are merged into a single group by name, leaving exactly 2 groups: 'Raj' and 'Rohit'.

Source: GATE CS 2015 (Session 1 / 7th Feb Shift 1) (2015)

This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.

Start revising free