SELECT `m`.`id` FROM `movies` AS `m` LEFT JOIN (SELECT `s`.`movie`, COUNT(`s`.`movie`) as count FROM `schedule` as `s` WHERE `s`.`date` > '2012-11-01' AND `s`.`date` <= '2012-11-02' GROUP BY `s`.`movie`) as j ON `j`.`movie` = `m`.`id` ORDER BY `j`.`count`