While using Zend_Db_Table
s and Zend_Db_Table_Select
with Zend_Db_Adapter_Pdo_Pgsql
, I am having a problem using a select query:
$rowset = $db->select()->from(array('a'=>'tablea'))
->columns(array('a.a'))
->join(array('b'=>'tableb'),'b.id = a.id', array('b.a'))
->query()->fetchAll();
Expected contents of rowset: (mainly the keys)
$rowset['a.a'] = "something";
$rowset['b.a'] = "somethingElse";
In the actual content of $rowset
, only $rowset['a']
exists, with no way to differentiate between the joined tables.
Any solutions to this?
When just doing a
$q = "SELECT * FROM tablea AS a
JOIN tableb AS b ON a.key = b.fkey";
$dbtable->getAdapter()->fetchAll($q);
I also don't get what I expect.
In order to differentiate between tables a and b when there are matching column names, you'll want to alias the columns in table b. The join would then look something like:
Please note that the 'ON' condition should be a string, not an array.