cancel
Showing results for 
Search instead for 
Did you mean: 

Column 'attribute_code' in order clause is ambiguous

Column 'attribute_code' in order clause is ambiguous

Hi,

We are using Manage Customer Attribute Extension and customized this to fetch records from the eav_attribute table and we are getting the exception as:

$entityTypeId = $this->entityModel->setType(
            \Magento\Customer\Model\Customer::ENTITY
        )->getTypeId();
        
        parent::_initSelect();
        //Join eav attribute table
        $this->getSelect()->joinLeft(
            ['eav_attribute' => $this->getTable('eav_attribute')],
            'eav_attribute.attribute_id = main_table.attribute_id'
        );
        $this->getSelect()->where('eav_attribute.entity_type_id=?',$entityTypeId);

When i am executing it getting below error as

 

Integrity constraint violation: 1052 Column 'attribute_code' in order clause is ambiguous, query was: SELECT `main_table`.*, `eav_attribute`.* FROM `vendor_mymarket_vendor_form_attribute` AS `main_table`
LEFT JOIN `eav_attribute` ON eav_attribute.attribute_id = main_table.attribute_id WHERE (eav_attribute.entity_type_id=9) ORDER BY attribute_code ASC

 

Can any one tell me solution for it?

1 REPLY 1

Re: Column 'attribute_code' in order clause is ambiguous

Hi @Kiran,

 

Do you need to call all fields from both tables?

attribute_code is present on both tables and that's the problem.

I guess you have 2 options:

 

  1. Include only the neccesary fields from the second table.
  2. Override the order by and use something like main_table.attribute_code