SELECT e.employee_name, e.employee_store, e.employee_phone, s.store_address
FROM `employee` e
JOIN store s ON e.employee_store = s.store_name
How to write this query in cakephp controller and how to display result in view part .
$this->Model->find(
'all',
array(
'fields' => array('table.employee_name', 'table.employee_store', ....),
'joins' => array(
'table' => 'databasename.store',
'conditions' => array('employee_store' => 'store_name')
)
)
)
if you join multiple database connection database are on same server otherwise not working
you should try this Employee is your Model name, stores is your table name and type is your joining left,right and inner
$details=$this->Employee->find('all',array('fields' => array('Employee.*','stores.*'),
'joins'=>array(
array(
'table'=>'store',
'type'=>'inner',
'conditions'=>array('Emmployee.employee_store=stores.store_name')
)
)
)
);