Adrian Veidt
Adrian Veidt

Reputation: 280

Php Mysql select query not working

The below query results in the following error:

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);

I don't have any other column to do the join. What am I supposed to do now?

Upvotes: 0

Views: 107

Answers (1)

Jamsheer Kandoth
Jamsheer Kandoth

Reputation: 192

AccountId put like finance_account.AccountId or ac.AccountId because query ambiguous on which table to look at

$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('ac.AccountId IN (?)', array_unique($parentIds)) ->setIntegrityCheck(false);

Upvotes: 1

Related Questions