Magento have a wide core functions and you dont need to write mysql query in order to get data from database. In some wired situation where you need to write a Mysql querym you can simple write below two line and you are done. Write MYSQL Query in Magento using below two line. Magento Customization.
$connection = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$connection->query(“Your Query Here”);