To find out the SQL query Magento uses to retrieve a specific collection, just do the following:
Let's say you would like to know what query is used to get a product collection - go to your debugging area (or maybe some phtml file), and paste following code:
$_productCollection = Mage::getResourceModel("catalog/product_collection"); $_productCollection->load(true);
Passing "true" as a parameter to the load function, will print out the query that Magento uses to retrieve the items for the collection.