以下查询会导致以下错误:
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/