Предпросмотр: Почему возникает ошибка Unknown column ''filmid'' in 'field list'?

Делаю такой запрос

->select("
    `fl_serial`.`id` AS serialid,
    `fl_serial`.`name_serial`,
    `fl_serial`.`slug_serial`,
    `fl_serial`.`description_serial`,
    `fl_serial`.`nesting` AS serialnesting,
    `fl_serial`.`year` AS serialyear,
    `fl_serial`.`country_title` AS serialcountry, 
    `fl_film`.`id` AS filmid, 
    `fl_film`.`name_film`, 
    `fl_film`.`slug_film`, 
    `fl_film`.`description_film`, 
    `fl_film`.`nesting` AS filmnesting, 
    `fl_film`.`year` AS filmyear, 
    `fl_film`.`country_title` AS filmcountry, 
    `fl_mfilm`.`id` AS mfilmid, 
    `fl_mfilm`.`name_mfilm`, 
    `fl_mfilm`.`slug_mfilm`, 
    `fl_mfilm`.`description_mfilm`, 
    `fl_mfilm`.`nesting` AS mfimnesting, 
    `fl_mfilm`.`year` AS mfilmyear, 
    `fl_mfilm`.`country_title` AS mfilmcountry, 
    `fl_cat_serial`.`id` AS catserialid, 
    COALESCE('serialid', 'filmid', 'mfilmid') AS `ids`, 
    COALESCE(`fl_serial`.`name_serial`, `fl_film`.`name_film`, `fl_mfilm`.`name_mfilm` ) AS `name`, 
    COALESCE(`fl_serial`.`slug_serial`, `fl_film`.`slug_film`, `fl_mfilm`.`slug_mfilm`) AS `slug`, 
    COALESCE(`fl_serial`.`description_serial`, `fl_film`.`description_film`, `fl_mfilm`.`description_mfilm`) AS `description`, 
    COALESCE('serialnesting', 'filmnestin', 'mfimnesting') AS `nesting`, 
    COALESCE('serialyear', 'filmyear', 'mfilmyear') AS `years`, 
    COALESCE('serialcountry', 'filmcountry', 'mfilmcountry') AS `country_title`")
    ->leftJoin('fl_serial','fl_cat_serial.id_serial = fl_serial.id')
    ->leftJoin('fl_film','fl_cat_serial.id_film = fl_film.id')
    ->leftJoin('fl_mfilm','fl_cat_serial.id_mfilm = fl_mfilm.id ')
    ->where(['fl_cat_serial.id_cat'=>$categoryThe->id])
    ->orderBy(['ids'=>SORT_DESC])
    ->groupBy('ids');


получаю такой ответ

Unknown column ''filmid'' in 'field list'
    The SQL being executed was: 
    SELECT COUNT(*) FROM (
    SELECT `fl_serial`.`id` AS `serialid`, 
    `fl_serial`.`name_serial`, 
    `fl_serial`.`slug_serial`, 
    `fl_serial`.`description_serial`, 
    `fl_serial`.`nesting` AS `serialnesting`, 
    `fl_serial`.`year` AS `serialyear`, 
    `fl_serial`.`country_title` AS `serialcountry`, 
    `fl_film`.`id` AS `filmid`, 
    `fl_film`.`name_film`, 
    `fl_film`.`slug_film`, 
    `fl_film`.`description_film`, 
    `fl_film`.`nesting` AS `filmnesting`, 
    `fl_film`.`year` AS `filmyear`, 
    `fl_film`.`country_title` AS `filmcountry`, 
    `fl_mfilm`.`id` AS `mfilmid`, 
    `fl_mfilm`.`name_mfilm`, 
    `fl_mfilm`.`slug_mfilm`, 
    `fl_mfilm`.`description_mfilm`, 
    `fl_mfilm`.`nesting` AS `mfimnesting`, 
    `fl_mfilm`.`year` AS `mfilmyear`, 
    `fl_mfilm`.`country_title` AS `mfilmcountry`, 
    `fl_cat_serial`.`id` AS `catserialid`, 
    COALESCE('serialid', `'filmid'`, 'mfilmid') AS `ids`, 
    COALESCE(`fl_serial`.`name_serial`, `fl_film`.`name_film`, `fl_mfilm`.`name_mfilm` ) AS `name`, 
    COALESCE(`fl_serial`.`slug_serial`, `fl_film`.`slug_film`, `fl_mfilm`.`slug_mfilm`) AS `slug`, 
    COALESCE(`fl_serial`.`description_serial`, `fl_film`.`description_film`, `fl_mfilm`.`description_mfilm`) AS `description`, 
    COALESCE('serialnesting', `'filmnestin'`, 'mfimnesting') AS `nesting`, 
    COALESCE('serialyear', `'filmyear'`, 'mfilmyear') AS `years`, 
    COALESCE('serialcountry', `'filmcountry'`, 'mfilmcountry') AS `country_title` 
    FROM `fl_cat_serial` 
    LEFT JOIN `fl_serial` ON fl_cat_serial.id_serial = fl_serial.id 
    LEFT JOIN `fl_film` ON fl_cat_serial.id_film = fl_film.id 
    LEFT JOIN `fl_mfilm` ON fl_cat_serial.id_mfilm = fl_mfilm.id 
    WHERE `fl_cat_serial`.`id_cat`=12 
    GROUP BY `ids`) `c`


причем если делаю такой запрос

SELECT 
    `fl_serial`.`id` AS serialid,
    `fl_serial`.`name_serial`,
    `fl_serial`.`slug_serial`,
    `fl_serial`.`description_serial`,
    `fl_serial`.`nesting` AS serialnesting,
    `fl_serial`.`year` AS serialyear,
    `fl_serial`.`country_title` AS serialcountry, 
    `fl_film`.`id` AS filmid, 
    `fl_film`.`name_film`, 
    `fl_film`.`slug_film`, 
    `fl_film`.`description_film`, 
    `fl_film`.`nesting` AS filmnesting, 
    `fl_film`.`year` AS filmyear, 
    `fl_film`.`country_title` AS filmcountry, 
    `fl_mfilm`.`id` AS mfilmid, 
    `fl_mfilm`.`name_mfilm`, 
    `fl_mfilm`.`slug_mfilm`, 
    `fl_mfilm`.`description_mfilm`, 
    `fl_mfilm`.`nesting` AS mfimnesting, 
    `fl_mfilm`.`year` AS mfilmyear, 
    `fl_mfilm`.`country_title` AS mfilmcountry, 
    `fl_cat_serial`.`id` AS catserialid,
     COALESCE('serialid', 'filmid', 'mfilmid') AS `ids`, 
     COALESCE(`fl_serial`.`name_serial`, `fl_film`.`name_film`, `fl_mfilm`.`name_mfilm` ) AS `name`, 
     COALESCE(`fl_serial`.`slug_serial`, `fl_film`.`slug_film`, `fl_mfilm`.`slug_mfilm`) AS `slug`, 
     COALESCE(`fl_serial`.`description_serial`, `fl_film`.`description_film`, `fl_mfilm`.`description_mfilm`) AS `description`, 
     COALESCE('serialnesting', 'filmnestin', 'mfimnesting') AS `nesting`, 
     COALESCE('serialyear', 'filmyear', 'mfilmyear') AS `years`, 
     COALESCE('serialcountry', 'filmcountry', 'mfilmcountry') AS `country_title` 
     FROM `fl_cat_serial` 
     LEFT JOIN `fl_serial` ON fl_cat_serial.id_serial = fl_serial.id 
     LEFT JOIN `fl_film` ON fl_cat_serial.id_film = fl_film.id 
     LEFT JOIN `fl_mfilm` ON fl_cat_serial.id_mfilm = fl_mfilm.id 
     WHERE `fl_cat_serial`.`id_cat`=12 
     ORDER BY `years` DESC LIMIT 60


то ответ получаю не подскажите в чем ошибка
  • Вопрос задан
  • 68 просмотров
Пригласить эксперта
Ответы на вопрос 1
slo_nik
@slo_nik Куратор тега Yii
Добрый вечер.
Сначала считайте(count), а потом выбирайте(select)
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы