Reputation: 75
I'm trying to join 2 tables (it'll be 4 in the end) but every attempt I take the result are all the rows from the first table.
This is my code
$select = $this->select()
->from('table1')
->join('table2', 'table1.table2_id = table2.table2_id', array('table2.table2_value2'))
->setIntegrityCheck(FALSE);
So this query will give me all the rows from table1.But I need some rows from table2 aswell. What am I doing wrong?
I'm only in a testing phase so don't mind the tablenames. I'm extending my model with Zend_Db_Table_Abstract
Thanks
Upvotes: 1
Views: 298
Reputation: 9719
The 3rd argument in the join statement is an array listing the columns you want from the 2nd table. Try leaving it out as per the instructions it will default to ALL coulmns:
The third argument to join() is an array of column names, like that used in the from() method. It defaults to "*", supports correlation names, expressions, and Zend_Db_Expr in the same way as the array of column names in the from() method.
To select no columns from a table, use an empty array for the list of columns. This usage works in the from() method too, but typically you want some columns from the primary table in your queries, whereas you might want no columns from a joined table.
If you are still not getting any items from the 2nd table, are you sure you sure you have items in the 2nd table which match, so table one has the id of a row in table 2, and the coulmns in table one and table two are 'table2_id'
Table One Structure for example:
table1_id
| user
| pass
| table2_id
| timestamp
Table Two Structure:
table2_id
| name
| number
| department
Upvotes: 1