OA. free
Free
Exl Core Cs & Systems Core Computer Science Medium

Consider the tables Student and Teacher: Table: Student Course Name Credits --- --- ---...

Exl technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Consider the tables Student and Teacher:

Table: Student

Course Name Credits
Bio-101 Jack 2
Phy-104 Bob 4
Che-102 Mike 3

Table: Teacher

Course Id
Bio-101 1000
Phy-104 1004
Mas-103 1003

What is the output of the following MySQL query?

SELECT * FROM Student RIGHT JOIN Teacher ON Student.Course = Teacher.Course;
Choose one option.
Show answer & explanation
Answer: A. | Course | Name | Credits | Course | Id | |---|---|---|---|---| | Bio-101 | Jack | 2 | Bio-101 | 1000 | | Phy-104 | Bob | 4 | Phy-104 | 1004 | | NULL | NULL | NULL | Mas-103 | 1003 |

A RIGHT JOIN returns all records from the right table (Teacher), and the matched records from the left table (Student). If there is no match, the result is NULL from the left side.

Step-by-step Derivation:
Step 1: Identify the join condition: Student.Course = Teacher.Course.
Step 2: Evaluate the right table (Teacher) records:

  • Row 1: 'Bio-101'. Matches Student table ('Bio-101', 'Jack', 2). Result: (Bio-101, Jack, 2, Bio-101, 1000).
  • Row 2: 'Phy-104'. Matches Student table ('Phy-104', 'Bob', 4). Result: (Phy-104, Bob, 4, Phy-104, 1004).
  • Row 3: 'Mas-103'. No match found in Student table. Since it is a RIGHT JOIN, the Teacher record is kept and Student columns are filled with NULL. Result: (NULL, NULL, NULL, Mas-103, 1003).
    Step 3: Note that 'Che-102' from the Student table is excluded because it does not exist in the Teacher table and this is not a LEFT or FULL join.
    Step 4: Combine results into the final table structure.