user2512996
user2512996

Reputation: 41

Inner join and null value

i have 3 tables

  1. table1
  2. table2
  3. table3

i am applying inner join on to retrieve the data from all these tables, but i am not getting any row as soon as any value inside any of the table is null can somebody tell me the correct way of doing this.

select name, subject, class
from table1 
inner join table2
on table1.subjectId = table2.subjectId
inner join table3
on table1.classId = table3.classId
where studentId = 3

on studentId 3 there is no subject in table2 and hence it is not giving any result for all of the tables.

Upvotes: 0

Views: 95

Answers (1)

Jeff M
Jeff M

Reputation: 477

use a left join.

select name, subject, class 
from table1
    left join table2 on table1.subjectId = table2.subjectId
    left join table3 on table1.classId = table3.classId
where studentId = 3 

Upvotes: 3

Related Questions