Welcome Guest, Not a member yet? Register   Sign In
MySQL - Issue with SELECT & GROUP BY [SOLVED]
#1

(This post was last modified: 11-29-2018, 09:03 AM by Coool6.)

Hello lovely CI Community,

I have a basic config MySQL 5.7 / PHP 7.0 with this DB : 
  • Pages Table 

  • Tags Table

  • Pages_Tags (Joint Table)
Query : 

Code:
$this->db->from("pages");
$this->db->select("*,GROUP_CONCAT('tags_name')");
$this->db->join('pages_tags', 'pages_tags.pages_id = pages.pages_id', 'left');
$this->db->join('tags', 'tags.tags_id = pages_tags.tags_id', 'left');       
$this->db->group_by("pages.pages_id");

and i have the following error : 

Code:
Expression #1 of SELECT list is not in GROUP BY clause and contains  nonaggregated column this is incompatible with sql_mode=only_full_group_by

So i made a lot of researches, and seems there are 2 solutions to fix it (more info here : https://dev.mysql.com/doc/refman/5.7/en/...dling.html) : 

1/ To change the SQL mode ===> I don't want to change the default config
2/ To have the same column in the SELECT & GROUP BY ===> I need a lot of columns in the SELECT and not only the ones in GROUP BY. Especially if the query is more complicated with a lot more LEFT JOIN. I need to display all theses infos.

Do you have any other solutions ? Alternative with other methods ? I'm open to anything Wink 

What i need is to get the list of pages and for each page the tags linked to, in one query.
It seems so easy but it doesn't work Big Grin 

Thanks a lot !!
Reply


Messages In This Thread
MySQL - Issue with SELECT & GROUP BY [SOLVED] - by Coool6 - 11-29-2018, 06:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB