S
S
Sergey Beloventsev2016-09-30 20:17:18
Yii
Sergey Beloventsev, 2016-09-30 20:17:18

Preview: Why does the Unknown column ''filmid'' in 'field list' error occur?

I make a request

->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');

I get this answer
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`

and if I make such a request
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

then I get the answer do not tell me what is the error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-09-30
@slo_nik

Good evening.
Count first, then select

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question