What is the output of the following SQL query? Employee Department…

2017

What is the output of the following SQL query?

Employee

Department

OT_allowance

RAMA

Mechanical

5000

GOPI

Electrical

2000

SINDHU

Computer

4000

MAHESH

Civil

1500

SELECT COUNT(*)

FROM ((SELECT Employee, Department FROM Overtime_allowance) AS S

NATURAL JOIN

(SELECT Department, OT_allowance FROM Overtime_allowance) AS T);

  1. A.

    16

  2. B.

    4

  3. C.

    8

  4. D.

    2

Attempted by 260 students.

Show answer & explanation

Correct answer: B

The SQL query performs a Natural Join between two subqueries derived from the same table, Overtime_allowance.

The first subquery selects Employee and Department columns, while the second selects Department and OT_allowance columns.

A Natural Join automatically matches rows based on common column names, which is 'Department' in this case.

The table contains 4 distinct employees (Rama, Gopi, Sindhu, Mahesh), each belonging to a unique department.

Since every department appears exactly once in both subqueries, the join operation pairs each row from the first subquery with its corresponding matching row in the second. This results in exactly 4 matched rows.

The COUNT(*) function then tallies these resulting rows.

Therefore, the output is 4.

Option A (16) and Option C (8) are incorrect because they assume a Cartesian product or duplicate matches, which do not occur here due to the unique department constraint.

Option D (2) is incorrect as it underestimates the total number of records in the table.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Isro