All Exams Test series for 1 year @ ₹349 only
Question

Consider the following relational schema:
Students (rollno: integer, name: string, age: integer, cgpa: real)
Courses (courseno: integer, cname: string, credits: integer)
Enrolled (rollno: integer, courseno: integer, grade: string)
Which of the following options is/are correct SQL query/queries to retrieve the names of the students enrolled in course number (i.e., courseno) 1470?

To solve the query question, we need to select the names of students enrolled in the course with course number 1470. We have the following relation schemas:

  • Students (rollno: integer, name: string, age: integer, cgpa: real)
  • Courses (courseno: integer, cname: string, credits: integer)
  • Enrolled (rollno: integer, courseno: integer, grade: string)

The task requires us to retrieve student names, hence we look at the Students and Enrolled tables. The key here is to match students’ roll numbers who are listed as enrolled in the specified course.

Let's analyze the options provided:

  1. Option 1:    SELECT S.name    FROM Students S    WHERE EXISTS (      SELECT *      FROM Enrolled E      WHERE E.courseno = 1470      AND E.rollno = S.rollno    );    

This query correctly identifies students enrolled in the course number 1470 by using the EXISTS clause to check if the student's roll number is present in the Enrolled table for the given course. This approach is valid and efficient.

  1. Option 2:    SELECT S.name    FROM Students S    WHERE SIZEOF (      SELECT *      FROM Enrolled E      WHERE E.courseno = 1470      AND E.rollno = S.rollno    ) > 0;    

This option is incorrect. In standard SQL, there is no SIZEOF function. Thus, this query is invalid due to using a non-existing SQL function.

  1. Option 3:    SELECT S.name    FROM Students S    WHERE 0 < (      SELECT COUNT(*)      FROM Enrolled E      WHERE E.courseno = 1470      AND E.rollno = S.rollno    );    

This query is also correct. It uses a subquery that counts the number of records in the Enrolled table where the course number is 1470 and student roll numbers match. The condition 0 < ensures that we get only those students who have at least one matching record in Enrolled.

  1. Option 4:    SELECT S.name NATURAL JOIN Enrolled E    FROM Students S E    WHERE E.courseno = 1470;    

This option is incorrect. The use of NATURAL JOIN syntax in this context is incorrect or incomplete, leading to syntax errors and incorrect query logic.

Conclusion: Based on the syntax and logical structure required for this query, Option 1 and Option 3 are correct choices. They appropriately filter students based on their enrollment in the specified course and retrieve the required names.

Was this answer helpful?

Important Questions from SQL

  1. Match the following -

    List IList II
    (a)DDL(i)LOCK TABLE
    (b)DML(ii)COMMIT
    (c)TCL(iii)Natural Difference
    (d)Binary operation(iv)REVOKE
  2. Which of the following is NOT a Structured Query Language Data type?

  3. Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column.

    We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form.

    Which of the following is/are correct?

    Employee
     

    EmpIDTeamID
    18
    28
    38
    47
    57
    69



    Output
     

    EmpIDTeamSize
    13
    23
    33
    42
    52
    61
  4. Let Account be a relation as shown. 

                                                                                                             Account

    AccNoBalance
    A15000
    A25000
    A310000
    A415000
    A518000

    Consider the given SQL query.

    SELECT AccNo FROM Account AS A 

    WHERE (SELECT COUNT(*) FROM Account AS B  

    WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)  

    FROM Account AS C WHERE A.Balance > C.Balance)

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

  5. 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 ________.

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App