SQL

GATE DA previous year questions · 3 questions

GATE DA 2025 | Question 33

NAT · 1 mark

On a relation named Loan of a bank:

Loan
loan_numberbranch_nameamount
L11Banjara Hills90000
L14Kondapur50000
L15SR Nagar40000
L22SR Nagar25000
L23Balanagar80000
L25Kondapur70000
L19SR Nagar65000

the following SQL query is executed.

SELECT L1.loan_number
FROM Loan L1
WHERE L1.amount > (SELECT MAX (L2.amount)
                   FROM Loan L2
                   WHERE L2.branch_name = 'SR Nagar');

The number of rows returned by the query is __________ (Answer in integer)

Explanation

Answer: 3

The inner query does not use L1, so it produces a single value: the largest SR Nagar amount, \(\max(40000, 25000, 65000) = 65000\).

The outer query keeps the loans whose amount is strictly greater than 65000: L11 (90000), L23 (80000) and L25 (70000). L19 is left out because 65000 is not greater than itself, and every other loan is smaller. So the query returns 3 rows.

Answer: 3

GATE DA 2025 | Question 56

MSQ · 2 marks

Consider the following two relations, named Customer and Person, in a database:

Person (
    aadhaar CHAR(12) PRIMARY KEY,
    name VARCHAR(32));
Customer (
    name VARCHAR(32),
    email VARCHAR(32) PRIMARY KEY,
    phone CHAR(10),
    aadhaar CHAR(12),
      FOREIGN KEY (aadhaar) REFERENCES Person(aadhaar));

Which of the following statements is/are correct?

Options for GATE DA 2025 | Question 56

Explanation

Answer: (B), (C)

Only the declared constraints restrict the columns.

  • A fails: the primary key of Customer is email, and aadhaar there is only a foreign key with no UNIQUE constraint. Several customer rows (say, one person with two email addresses) can share the same aadhaar, so it is not a candidate key.
  • B holds: phone has no NOT NULL or key constraint, so it may be NULL.
  • C holds: aadhaar is the primary key of Person, and a primary key is always a candidate key.
  • D fails: a primary key column can never be NULL.

Answer: B, C

GATE DA 2024 | Question 31

NAT · 1 mark

Consider the following two tables named Raider and Team in a relational database maintained by a Kabaddi league. The attribute ID in table Team references the primary key of the Raider table, ID.

Raider
IDNameRaidsRaidPoints
1Arjun200250
2Ankush190219
3Sunil150200
4Reza150190
5Pratham175220
6Gopal193215
Team
CityIDBidPoints
Jaipur2200
Patna3195
Hyderabad5175
Jaipur1250
Patna4200
Jaipur6200

The SQL query described below is executed on this database:

SELECT *
FROM Raider, Team
WHERE Raider.ID=Team.ID AND City=“Jaipur” AND
RaidPoints > 200;

The number of rows returned by this query is ______.

Explanation

Answer: 3

The condition Raider.ID=Team.ID turns the cross product into a join that pairs each Team row with the raider of the same ID. Of these pairs, keep only the Jaipur rows whose raider has more than 200 raid points:

  • Jaipur, ID 2: Ankush with 219 points, kept.
  • Jaipur, ID 1: Arjun with 250 points, kept.
  • Jaipur, ID 6: Gopal with 215 points, kept.

The Patna and Hyderabad rows fail the city test. Note that the comparison is strict, so a raider with exactly 200 points (Sunil) would not count, but he is in Patna anyway. The query returns 3 rows.

Answer: 3