Any2Quiz
Computer Science / Languages / SQL

Joins Quiz - Languages SQL

Free practice quiz: Joins (Languages SQL). 50 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

Play all 50 questions free

Sample questions

  1. Which type of JOIN returns all rows from the left table and the matched rows from the right table? If there is no match, the result is NULL from the right side.

    1. INNER JOIN
    2. LEFT JOIN
    3. RIGHT JOIN
    4. FULL OUTER JOIN
    Show answer

    Answer: B. LEFT JOIN

    A LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table (the table specified before the JOIN keyword) and the matched rows from the right table. If a row in the left table does not have a corresponding match in the right table, the columns from the right table will contain NULL values.

  2. When using a RIGHT JOIN, the join condition is evaluated against which table first?

    1. The left table
    2. The right table
    3. Both tables simultaneously
    4. The table with fewer rows
    Show answer

    Answer: B. The right table

    In a RIGHT JOIN, all rows from the right table are included. The join condition is used to find matching rows in the left table. If there's no match in the left table, NULLs are returned for the left table's columns.

  3. Which JOIN would you use to find all customers and the count of orders they have placed, including customers who have placed zero orders?

    1. INNER JOIN
    2. LEFT JOIN
    3. RIGHT JOIN
    4. FULL OUTER JOIN
    Show answer

    Answer: B. LEFT JOIN

    You would use a `LEFT JOIN` from `Customers` to `Orders`. Then, you would `GROUP BY` customer and use `COUNT(Orders.OrderID)` (or a similar aggregate function that counts non-NULL values) to get the number of orders. Customers with no orders will have a count of 0.

  4. What is the purpose of the `USING` clause in SQL JOINs?

    1. To specify multiple join conditions.
    2. To join tables without a common column name.
    3. To join tables on columns that have the same name in both tables, simplifying the ON clause.
    4. To define the order of columns in the result set.
    Show answer

    Answer: C. To join tables on columns that have the same name in both tables, simplifying the ON clause.

    The `USING` clause is a shorthand for the `ON` clause when the join columns in both tables have the exact same name. For example, `JOIN table2 USING (common_column)` is equivalent to `JOIN table2 ON table1.common_column = table2.common_column`.

  5. Consider the following two tables: `Students` (StudentID, StudentName) `Enrollments` (EnrollmentID, StudentID, Course) Which query would display all students and the courses they are enrolled in, including students who are not enrolled in any course?

    1. `SELECT * FROM Students INNER JOIN Enrollments ON Students.StudentID = Enrollments.StudentID;`
    2. `SELECT * FROM Students LEFT JOIN Enrollments ON Students.StudentID = Enrollments.StudentID;`
    3. `SELECT * FROM Enrollments LEFT JOIN Students ON Enrollments.StudentID = Students.StudentID;`
    4. `SELECT * FROM Students RIGHT JOIN Enrollments ON Students.StudentID = Enrollments.StudentID;`
    Show answer

    Answer: B. `SELECT * FROM Students LEFT JOIN Enrollments ON Students.StudentID = Enrollments.StudentID;`

    A `LEFT JOIN` with `Students` as the left table ensures that all students are included in the result. If a student is not enrolled in any course, the `Enrollments` columns (like `Course`) will be NULL for that student.

Take the full quiz

More quizzes

Browse all SQL quizzes