Many times i am debugging SQL Query in Magento. But i am little confuse about usages of main_table in SQL query in Magento.

I can't find any table named with "main_table" in database.

Can anyone tell me the concept about main_table in Magento.

1 Answer 1


main_table is an alias of your table name i.e. you have table name abc in the following SQL query.

SELECT `main_table`.* FROM `abc` AS `main_table` ORDER BY `main_table`.`bid_end` desc

Magento collection will default generate alias of your table i.e. abc as main table.

  • Means i create collection as: $collection = Mage::getResourceModel($this->_getCollectionClass()); and i get query as below: SELECT main_table.* FROM sales_flat_order_grid AS main_table that means sales_flat_order_grid is my main table...Right ??
    – vijay rami
    Commented Jul 24, 2016 at 7:51
  • you can check echo Mage::getResourceModel('sales/order_collection')->getSelect(); Commented Jul 24, 2016 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.