SQL correct way of joining if the other parameter is null

后端 未结 5 1421
离开以前
离开以前 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:52

    select s.firstname, s.lastname, q.id as not_taken_quiz_id, q.quiz_name as not_taken_quiz_name
    from #student s
    left join #quiz_details qd on s.id = qd.student_id
    left join #quiz q on q.id <> qd.quiz_id
    

    This will give you each student along with the quiz that they have not taken.

提交回复
热议问题