mysql - codeigniter join with same columns -
mysql - codeigniter join with same columns -
i working on educational project came across simple logic. have 2 table month , semester_type. bellow schema , data;
month table
month_id month_name month_value lupdate 1 jan 1 2 feb 2 3 march 3 4 apr 4 5 may 5 6 june 6 7 july 7 8 august 8 9 september 9 10 oct 10 11 nov 11 12 dec 12
here semester_type table;
semester_type_id semester_type_name start_month end_month 1 fall 8 12 2 summer 1 4
and here output want;
semester name start month end month fall august dec summer jan apr
i confused inner joining month_id start_month , end_month columns in both tables. can help me codeigniter query
join month's table twice semester table
select s.semester_type_name, m.month_name start_month , m1.month_name end_month semester s bring together month m on(m.month_id = s.start_month) bring together month m1 on(m1.month_id = s.end_month)
demo
using codeigniter's active record library can write as
$this->db->select('s.semester_type_name,m.month_name start_month ,m1.month_name end_month') ->from('semester s') ->join('month m','m.month_id = s.start_month') ->join('month m1','m1.month_id = s.end_month') ->get() ->result();
mysql codeigniter join inner-join
Comments
Post a Comment