How to get a custom SQL query result in magento

How to get a custom SQL query result in magento

$qurey = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$queryresult = $qurey->query(“select * from tablename “);
while ($rows = $queryresult->fetch() )
{
$categoryIds[]=$rows[‘id’];
}

Hope it will work.