连接表覆盖列
在使用 Zend_Db_Table
和 Zend_Db_Table_Select
与 Zend_Db_Adapter_Pdo_Pgsql
时,我在使用选择查询时遇到问题:
$rowset = $db->select()->from(array('a'=>'tablea'))
->columns(array('a.a'))
->join(array('b'=>'tableb'),'b.id = a.id', array('b.a'))
->query()->fetchAll();
行集的预期内容:(主要是键)
$rowset['a.a'] = "something";
$rowset['b.a'] = "somethingElse";
$rowset
的实际内容中,只有 $rowset['a']
存在,无法区分连接的表。
有什么解决办法吗?
当我刚做的时候,
$q = "SELECT * FROM tablea AS a
JOIN tableb AS b ON a.key = b.fkey";
$dbtable->getAdapter()->fetchAll($q);
我也没有得到我所期望的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了在存在匹配的列名时区分表 a 和表 b,您需要为表 b 中的列指定别名。然后,连接将类似于:
请注意,“ON”条件应该是字符串,而不是数组。
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.