A relational database contains two tables student and department in which…

2004

A relational database contains two tables student and department in which student table has columns roll_no, name and dept_id and department table has columns dept_id and dept_name. The following insert statements were executed successfully to populate the empty tables:

Insert into department values (1, 'Mathematics')
Insert into department values (2, 'Physics')
Insert into student values (l, 'Navin', 1)
Insert into student values (2, 'Mukesh', 2)
Insert into student values (3, 'Gita', 1) 

How many rows and columns will be retrieved by the following SQL statement?

Select * from student, department

  1. A.

    0 row and 4 columns

  2. B.

    3 rows and 4 columns

  3. C.

    3 rows and 5 columns

  4. D.

    6 rows and 5 columns

Attempted by 801 students.

Show answer & explanation

Correct answer: D

Answer: 6 rows and 5 columns

Explanation: The SELECT statement with multiple tables and no join condition produces a Cartesian product (cross join) of the rows.

  • Count rows in student: 3 (Navin, Mukesh, Gita).

  • Count rows in department: 2 (Mathematics, Physics).

  • Rows in result = 3 × 2 = 6 (Cartesian product).

  • Columns: student has 3 columns (roll_no, name, dept_id) and department has 2 columns (dept_id, dept_name), so total columns = 3 + 2 = 5. Note that dept_id appears twice in the result.

Therefore, the query returns 6 rows and 5 columns.

Explore the full course: Gate Guidance By Sanchit Sir