I want to make inner join between two tables
Visit table has
- visit_id
- target
Report table has
- rep_id
- visit_id
Each visit has many reports ,I want to select all reports with specified visit target
I make like this but it donesn't work
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select();
$rows = $select->from('visits_tb', array('target', 'visit_id'))
->joinInner('report_tb', 'visits_tb.visit_id= report_tb.visit_id', array('visit_id', 'rep_id'))
->where("visits_tb.visit_id=$id");
ZF uses inner join by default so joinInner == join . Since name of FK = PK hence you can use joinUsing .
What happens if you turn it the other way around?
Have not tested the code, but looked more correct i my eyes, if you wanted to output all lines from the Report table, with a specified target.
You can try the following; maybe its a bit clearer if you use table aliases:
I think better solution is to use Zend's relationship in this case
http://framework.zend.com/manual/en/zend.db.table.relationships.html
With this config You should be able to fetch dependent rowset with reports
What's beneficial You can instantly go on and process results