Welcome Guest, Not a member yet? Register   Sign In
Joining Joined Tables
#1

[eluser]Unknown[/eluser]
I am stuck in generating SQL statement for joining tables.

Basically I have 4 tables. And there are 2 tables with foreign key. Table Sequence is connected to Product table and Region Table. And Distribution table is connected to sequence table.

Table Products.

id | product_desc

Table Region.

id | region_desc

Table Sequence.

id | product_id | region_id

Table Distributions

id | sequence_id | sales | distribution_fee

Here's my code

Code:
$this->db->select('*');
$this->db->from('distributions');
$this->db->join('sequence', 'sequence.id = distributions.sequence_id', 'left');
$this->db->join('sequence', 'sequence.product_id=products.product_no'); //Generates Error
$this->db->join('sequence', 'sequence.region_id=regions.id'); // Generates Error
$this->db->order_by('distributions.id','asc');        
$query = $this->db->get();
if($query->num_rows() != 0){
   return $query->result_array();
} else {    
  return false;
}

any help is highly appreciated. Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB