• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.