Practice mode DBMS and SQL

Table Dept(id, name) has rows (10,’HR’), (20,’IT’), (30,’Ops’). Table Emp(id, name, dept_id) has rows (1,’Ali’,10), (2,’Sara’,20), (3,’Omar’,20), (4,’Zara’,NULL). SELECT COUNT(*) FROM Emp e INNER JOIN Dept d ON e.dept_id = d.id; What is the result?

Correct answer D. 3

Explanation

An inner join keeps only pairs of rows where the join condition is true. Ali matches HR and Sara and Omar match IT, which gives 3 rows. Zara's dept_id is NULL, and NULL = 10 is not true, so Zara drops out. Ops has no employees, so it contributes nothing. The answer 12 is the cross-join size (4 x 3), which you get only with no join condition.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.