Наконец, у меня есть ответ с помощью М.Хеманта
$this->db->select('u.user_id,
u.name as user_name,
u.branch as branch_id,
b.name as branch_name,
r.courses_id,c.courses_name,
r.days_type,d.package_description as package_name,
r.valid_from,
r.valid_to,
r1.valid_from as next_valid_from,
r1.valid_to as next_valid_to,
r.course_time_table_id,
t.from_time,
t.to_time,
u1.user_id as teacher_id,
u1.name as teacher_name,
u2.user_id as dietitian_id,
u2.name as dietitian_name,
p.gender,
u.status')
->from('userdetail u')
->join('branch b','b.id = u.branch','LEFT')
->join("(SELECT * FROM rejoin WHERE '{$today}' BETWEEN valid_from AND valid_to ) as r ",'r.member_id = u.user_id','LEFT')
->join("(SELECT * FROM rejoin WHERE '{$today}' < valid_from AND valid_to ) as r1 ",'r1.member_id = u.user_id','LEFT')
->join('courses c','c.courses_id = r.courses_id','LEFT')
->join('days_package d', 'd.package_name = r.days_type','LEFT')
->join('timetable t','t.course_time_table_id =r.course_time_table_id','LEFT')
->join('personaldetail p','p.user_id = u.user_id','LEFT')
->join('userdetail u1','u1.user_id = u.tech_assign','LEFT')
->join('userdetail u2','u2.user_id = u.p_assinged_dit','LEFT')
->where('u.usr_acc_typ','p')
->where('u.status','Active')
->get();