SQL Joins questions and answers

Inner, left, right, full, cross and self joins, and row counts. Practise sql joins questions from the sql section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample sql joins questions with worked answers

Question 1

In A LEFT JOIN B, what happens to a row of A that has no matching row in B?

  1. It is dropped from the result
  2. It is paired with every row of B
  3. It appears once, with B's columns copied from the previous matched row
  4. It appears once, with NULL in every column that comes from B

Answer: D. It appears once, with NULL in every column that comes from B

Explanation: A left join keeps every row of the left table. When there is no match, the right table's columns are filled with NULL so the left row is not lost.

Question 2

Tables Authors(author_id, name) and Books(book_id, title, author_id) exist. Which query lists every author with their book titles, including authors who have not written any book?

  1. SELECT a.name, b.title FROM Authors a INNER JOIN Books b ON a.author_id = b.author_id;
  2. SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id;
  3. SELECT a.name, b.title FROM Books b LEFT JOIN Authors a ON a.author_id = b.author_id;
  4. SELECT a.name, b.title FROM Authors a RIGHT JOIN Books b ON a.author_id = b.author_id;

Answer: B. SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id;

Explanation: The table whose rows must all be kept, Authors, has to be on the preserved side. Authors LEFT JOIN Books does that; the inner join drops authors without books, and the other two preserve Books instead.

Question 3

Table A has m rows. Table B has n rows and B.k is its primary key. How many rows does A LEFT JOIN B ON A.k = B.k return?

  1. Exactly n
  2. m + n
  3. Anything from m to m × n, depending on the data
  4. Exactly m

Answer: D. Exactly m

Explanation: Because B.k is unique, a row of A can match at most one row of B, so no A row is duplicated. The left join also keeps the A rows that match nothing, so the result has exactly m rows.

All 20 sql joins questions with answers

SQL Joins: common questions

What are sql joins questions?

Inner, left, right, full, cross and self joins, and row counts. They appear in the sql section of many placement tests.

Where can I practise sql joins questions with answers for free?

Right here on LogicWiz Exams. Every sql joins question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise sql joins?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of sql joins questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: SQL practice.

More sql topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep