Php Mysql 选择查询不起作用

标签 php mysql zend-framework zend-framework2

以下查询会导致以下错误:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'AccountId' in where clause is ambiguous

$select = $this->select()
            ->from(array('finance_account' => DB_TABLE_PREFIX . 'finance_account'), array(
                    'AccountId',
                    'ParentAccountId',
                    'AccountGroupId',
                    'AccountPath',
                    'AccountCode',
                    'AccountName',
                    'Description'
                ))
            ->joinLeft(array('ac' => DB_TABLE_PREFIX . 'customer'), 'finance_account.AccountId = ac.AccountId', array())
                    // using "array_unique()" to minimize db overhead
             ->where('AccountId IN (?)', array_unique($parentIds))
            ->setIntegrityCheck(false);

我没有任何其他列可以进行连接。我现在该怎么办?

最佳答案

AccountId 类似于 Finance_account.AccountId 或 ac.AccountId,因为查询不明确要查看哪个表

$select = $this->select() ->from(array('finance_account' => DB_TABLE_PREFIX . 'finance_account'), array( '帐户ID', '父账户ID', '账户组ID', '帐户路径', '账户代码', '帐户名称', '描述' )) ->joinLeft(array('ac' => DB_TABLE_PREFIX . '客户'), 'finance_account.AccountId = ac.AccountId', array()) //使用“array_unique()”来最小化数据库开销 ->where('ac.AccountId IN (?)', array_unique($parentIds)) ->setIntegrityCheck(false);

关于Php Mysql 选择查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30174086/

相关文章:

php - 从数据库获取个人帖子

php - MySQL Rank 产品下载

mysql - 日期字段未在 sql 中正确排序

php - Zend Framework select() 给出意外的 SQL

php - 重命名关联数组中新添加元素的键

php - 选择每个成员的最后一条消息

php - Laravel 4 union 生成错误的 SQL

mysql - 在ubuntu上安装mysql后访问被拒绝

zend-framework - ZF2 : change view script from controller factory

php - Zend 框架 : How to read email attachments (and save to disk)?