Select distinct case when BranchCourseId is null then Tb_Client.ThreePhaseKind else BranchCourseId end BranchCourseId
, Tb_Client.* from Tb_Client
inner join Tb_Class_Client on Tb_Client.id = Tb_Class_Client.clientId
inner join Tb_Class on tb_class_client.classid = tb_class.id
inner join tb_course on tb_class.courseid = tb_course.id