0

I need one help. I need to join two table using multiple column in CodeIgniter. I am explaining my table below.

pt_car_locations

  id     pickup_location_id       dropoff_location_id       price
   1           21                           22                100    
   2           23                           24                200

pt_locations id location 21 Cappa 22 United 23 Mascut 24 ABCD

Here I need to retrieve the pickup and drop location by joining both table. I am explaining query below.

$this->db->select('cl.pickup_location_id,cl.dropoff_location_id,cl.price,l.id,l.location');
$this->db->from('pt_car_locations as cl');
$this->db->join('pt_locations as l', 'cl.pickup_location_id = l.id', 'inner');

Here I need to join both column and get the both location in each row.

0

1 Answer 1

1

could be you need the join twice one with table alias l and one with table alias l2

$this->db->select('cl.pickup_location_id,cl.dropoff_location_id,cl.price,l.id,l.location');
$this->db->from('pt_car_locations as cl');
$this->db->join('pt_locations as l', 'cl.pickup_location_id = l.id', 'inner');
$this->db->join('pt_locations as l2', 'cl.dropoff_location_id = l2.id', 'inner');
Sign up to request clarification or add additional context in comments.

Comments