SQL correct way of joining if the other parameter is null

后端 未结 5 1425
离开以前
离开以前 2021-02-02 06:07

I have this code and its temporary tables so you can run it.

create table #student
(
    id int identity(1,1),
    firstname varchar(50),
    lastname varchar(50         


        
5条回答
  •  日久生厌
    2021-02-02 06:42

    Pretty sure you want something along these lines. This will give you the quiz values and return NULL for the student and quiz_details when there is no matching data.

    select *
    from #quiz q
    left join #quiz_details qd on q.id = qd.quiz_id
    left join #student s on s.id = qd.student_id
    

提交回复
热议问题