SELECT `c`.`id`, `c`.`url_code`, `c`.`tpl_id`, `m`.`language_id`, `l`.`host_name` FROM company AS `c` LEFT JOIN `company_lang` AS `m` ON (`m`.`company_id` = `c`.`id`) RIGHT JOIN `languages` AS `l` ON (`m`.`language_id` = `l`.`id` AND `l`.`status` = 1) WHERE `c`.`url_code` != '' AND `c`.`tpl_id` > 0 AND `c`.`status` = 1