Hello Magento friends today's i'm share with you to How to print sql query in Magento
try this example :
<?php
$collection = Mage::getModel(‘catalog/category’)->load($categoryId)
->getProductCollection()
->addAttributeToSort(‘name’, ‘ASC’);
echo $collection->printlogquery(‘true’)
.png)