By Engine23

Magento - Get the sql for a collection

If you ever were curious about what the SQL is being built for a Magento Collection, its really, really easy

$collection = Mage::getModel('poll/poll')->getResourceCollection()
->addFieldToFilter('date_posted', array('from' =>'2014-02-01 00:00:00', 'to'=>'2014-02-28 23:59:59'));

The result will be something similar to this:

SELECT `main_table`.* FROM `poll` AS `main_table` WHERE (date_posted >= '2014-02-01 00:00:00' AND date_posted <= '2014-02-28 23:59:59')