Answer the question
In order to leave comments, you need to log in
Codeigniter3, how to select info from three tables in one query?
Hello, need help!
There are three tables
orders
products
alias
You need to select all records from orders, add all records from alias by id (by alias_id which is in orders) + add info from products by orders_id (which is in orders - id )
I try like this
public function test()
{
$query = $this->db->select('*')
->from('products')
->join('orders', 'order_id = order_id')
->join('alias', 'alias_id = alias_id')
->get();
print_r($query->result_array());
}
Error Number: 1052
Column 'alias_id' in on clause is ambiguous
SELECT * FROM `scm_products` JOIN `scm_orders` ON `order_id` = `order_id` JOIN `scm_alias` ON `alias_id` = `alias_id`
Filename: C:/Users/user/Dropbox/MAMPfiles/scm.loc/web/application/models/Buyer_model.php
Line Number: 36
Answer the question
In order to leave comments, you need to log in
public function test()
{
$query = $this->db->select('p.*' )
->from('products p')
->join('orders o', 'o.order_id = p.order_id')
->join('alias a', 'a.alias_id = p.alias_id')
->get();
print_r($query->result_array());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question