Magento View SQL For Collection

If you are working with collections and would like to verify that the actual SQL being used is what you expect it to be then this little tip might prove really handy.

For any collection you can call the method getSelect(). This retrieves the actual Select object that handles the query.

If you cast this select object to a string, you get the raw SQL query, so for example the following is pretty handy:

die(var_dump((string)$collection->getSelect()));

This way you can tweak your collection filters etc and check that its doing what you expect it to be doing