How to return all the rows from t1 using LEFT JOIN of t3 in SQL

35 Views Asked by At
t1 (addition)
-----
id
t2_fk (modelpaper)
questions (100 questions)

t2 (modelpaper)
-----
id

t3 (student answers)
-----
id
t1_fk 
t2_fk
ans (out of 100 they completed only 75)

I want to join t3 and still show all 100 questions. But when i do (see 3rd one) it showed me different number. how can i do that.

SELECT COUNT(id) FROM t1 
WHERE t2_FK = 60
// 100

SELECT COUNT(t1.id) FROM t1 LEFT JOIN t2 ON t2.id = t1.t2_fk 
WHERE t1.t2_FK = 60
// 100

SELECT COUNT(t1.id) FROM t1 LEFT JOIN t2 ON t2.id = t1.t2_fk LEFT JOIN t3 ON t2.id = t3.t2_fk 
WHERE t1.t2_FK = 60
// 4600
0

There are 0 best solutions below