Homechevron_rightEngineeringchevron_rightRPSC Programmerchevron_rightProgrammer DBMSchevron_rightJoins

Joins MCQs

  • 1.

    Consider the following two tables and four queries in SQL.

    Book (isbn, bname), Stock (isbn, copies)

    Query 1:

    SELECT B.isbn, S.copies
    FROM Book B INNER JOIN Stock S
    ON B.isbn = S.isbn;
    

    Query 2:

    SELECT B.isbn, S.copies
    FROM B B LEFT OUTER JOIN Stock S
    ON B.isbn = S.isbn;

    Query 3:

    SELECT B.isbn, S.copies
    FROM Book B RIGHT OUTER JOIN Stock S
    ON B.isbn = S.isbn;

    Query 4:

    SELECT B.isbn, S.copies
    FROM B B FULL OUTER JOIN Stock S
    ON B.isbn = S.isbn;

    Which one of the queries above is certain to have an output that is a superset of the outputs of the other three queries?

  • filter_dramaExplanation
    Answer is : D

    In SQL the FULL OUTER JOIN combines the results of both left and right outer joins and returns all (matched or unmatched) rows from the tables on both sides of the join clause.

    So, option (D) is correct.

  • 2.

    Given two tables R1(x, y) and R2(y, z) with 50 and 30 number of tuples respectively. Find maximum number of tuples in the output of natural join between tables R1 and R2 i.e. R1 * R2? (*. Natural Join)

  • filter_dramaExplanation
    Answer is : D

    Concept:

    A natural join is based on common attributes or common columns to join two tables or relations.

    Explanation:

    Consider an example, suppose there are two tables Employee(Eid, Ename) consists of 5 tuples and department(Eid, Did) consists of 3 tuples only.

    Eid

    Ename

    1

    E1

    1

    E2

    1

    E3

    1

    E4

    1

    E5

     

    Eid

    Did

    1

    D1

    1

    D2

    1

    D3

     

    Natural join of employee and department(Employee * Department) gives:

    5 × 3 = 15

    So, maximum number of tuples in natural join are from the relation having minimum tuples. So, in given question, R2 contains 30 tuples, so , maximum number of tuples in the output of natural join between tables R1 and R2 i.e. R1 * R2 = 50 × 30 = 1500.

  • 3.

    Which of the following Relational Algebra operations can be used when you want to keep all the tuples of the first relation irrespective of whether or not they have matching tuples in the second relation?

  • filter_dramaExplanation
    Answer is : B

    The answer to the above question is Option 2) Left-outer Join
    A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

    Here are the different types of the JOINs in SQL:

    1. (INNER) JOIN: Returns records that have matching values in both tables
    2. LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table
    3. RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table
    4. FULL (OUTER) JOIN: Returns all records when there is a match in either left or right table

    We can see that left join keeps all the elements from the first relation irrespective of their presence in second relation.

  • 4.

    In RDBMS, which type of Join returns all rows that satisfy the join condition ?

  • filter_dramaExplanation
    Answer is : A

    Concept:

    Join operation is used to combine related tuples from two relations into single tuples. Join operation can be stated in terms of Cartesian product followed by SELECT operation.

    Join condition form: ANDAND……AND

    Explanation:

    There are various variations of join operations such as equi-join, natural join, theta join, inner join, outer join.

    • Natural join is performed by equating all attributes pairs that have the same name in the two relations.
    • Join operation with equality condition is known as equi-join.
    • Join operation which is used to combine data from multiple relations so that related information can be presented in a single table is known as inner join. Inner join is a type of match and merge operations defined as combination of Cartesian product and selection.
    • Outer join can be used when we want to keep all the tuples in the result of join regardless of whether or not they have matching tuples in other relation.
  • 5.

    A condition is referred to as __________

  • filter_dramaExplanation
    Answer is : B

    An SQL join clause combines records from two or more tables in a database. It creates a set that can be saved as a table or used as it is. A JOIN is a means for combining fields from two tables by using values common to each.

  • 6.

    Which product is returned in a join query have no join condition:

  • filter_dramaExplanation
    Answer is : B

    A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a pair of numerical coordinates.

    A CROSS JOIN or CARTESIAN JOIN returns the Cartesian product of an available set of records from multiple joined tables. Thus, this join would equate to an inner join in which the join-condition always evaluates to either True or wherever the join-condition is not present in the statement.

  • 7.

    Which join refers to join records from the write table that have no matching key in the left table are include in the result set:

  • filter_dramaExplanation
    Answer is : B

    A right outer join will return all the rows that an inner join returns plus one row for each of the other rows in the second table that did not have a match in the first table. It is the same as a left outer join with the tables specified in the opposite order.

    Outer joins are of following three types.

    1. Left outer join
    2. Right outer join
    3. Full outer join

    Right Outer Join : The right join operation returns all record from right table and matching records from the left table. On a matching element not found in left table, NULL is represented in that case.

     

  • 8.

    Which operation are allowed in a join view:

  • filter_dramaExplanation
    Answer is : D

    The DELETE statement is used to delete rows in a table. The UPDATE statement is used to update existing records in a table. The INSERT INTO statement is used to insert new records in a table.

  • 9.

    Which view that contains more than one table in the top-level FROM clause of the SELECT statement:

  • filter_dramaExplanation
    Answer is : C

    The DELETE statement is used to delete rows in a table. The UPDATE statement is used to update existing records in a table. The INSERT INTO statement is used to insert new records in a table.

  • 10.

    What is Join Operation denoted by?

  • filter_dramaExplanation
    Answer is : D

    Join Operation is denoted by ⋈.

    A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

leaderboardLeaderboard
  • Rahul Kumar

    191 Points

  • VIKRAM JEET

    54 Points

  • GEETHIKA CHOWDARY

    53 Points

  • sunita saini

    52 Points

  • Zain

    49 Points