0

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user2512996
  • 41
  • 1
  • 4
  • This is how it's meant to work. Maybe you want an outer join of some kind. – John Saunders Jun 28 '13 at 01:22
  • Here is a [good Venn Diagram](http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html) that helps illustrate what the different types of joins do. You all of Table A but you also want Table B where it is available. – Scott Chamberlain Jun 28 '13 at 01:24

1 Answers1

3

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 
Jeff M
  • 477
  • 2
  • 5