group-concat

Need help again about joining tables

半城伤御伤魂 提交于 2019-12-02 16:38:04
问题 some context I asked a question about a MySQL request, my post can be found there: Need help about joining tables Now I have another problem related to that, so on my page I'm listing tickets from a database my request is: "SELECT glpi_tickets.id, glpi_tickets.name, GROUP_CONCAT( CASE WHEN glpi_tickets_users.type = 1 THEN CONCAT(glpi_users.firstname, ' ', glpi_users.realname) END) AS creator, GROUP_CONCAT( CASE WHEN glpi_tickets_users.type = 1 THEN CONCAT(glpi_tickets_users.users_id) END) AS

Include null results in group_concat

隐身守侯 提交于 2019-12-02 06:49:48
I have two tables like this profile_answers +---------+------------+ | id | class_name | +---------+------------+ | 1 | Class 1 | | 2 | Class 2 | | 3 | Class 1 | +---------+------------+ educations +---------+--------------------+------------+ | id | profile_answers_id | sample | +---------+--------------------+------------+ | 1 | 1 | 1234 | | 2 | 1 | 2334 | | 3 | 1 | 3434 | +---------+------------+--------------------+ I ran the query, select educations.profile_answer_id, GROUP_CONCAT(educations.sample) from educations LEFT JOIN profile_answers ON educations.profile_answers_id = profile

MySQL: GROUP_CONCAT with an ORDER BY COUNT?

梦想与她 提交于 2019-12-02 05:53:32
Is this possible ? Let's say I have a list of addresses, with a lot of duplicate entries. I need to filter out all the duplicates, because some addresses have slightly different names but the same postalcode and telephone number. First I do a GROUP BY on postalcode and telephone. SELECT name, address, postalcode, place, phone FROM addresses GROUP BY postalcode, phone But then I get random names. I would like to get the best name, that is, the name with the most entries per postalcode/phone. So I thought of the following. Here I use the SUBSTRING_INDEX function to only get the first item in the

GROUP_CONCAT change GROUP BY order

爱⌒轻易说出口 提交于 2019-12-01 18:07:32
I have a VIEW (lots of joins) that outputs data ordered by a date ASC . Works as expected. OUTPUT similar to: ID date tag1 other_data 1 25-03-2011 blue fff <= 1 26-03-2011 red ggg 1 27-03-2011 pink yyy 2 25-03-2011 red yyy <= 2 26-03-2011 orange rrr If I apply a GROUP BY ID . For the other columns MySQL outputs the first found row of each ID. I read this somewhere in te docs. SELECT * FROM `myVIEW` GROUP BY `ID` ID date tag1 other_data 1 25-03-2011 blue fff <= 2 25-03-2011 red yyy <= Now lets add a GROUP_CONCAT( tags1 ) SELECT *,CONCAT_GROUP(`tag1`) AS `tags` FROM `myVIEW` GROUP BY `ID` Since

Set group_concat_max_len on a PDO query

独自空忆成欢 提交于 2019-12-01 16:47:11
I have the following query: $cases = $conn->prepare("SELECT GROUP_CONCAT(text SEPARATOR '|') as texts, year FROM cases GROUP BY year ORDER BY ano DESC"); $cases->execute(); $cases_result = $cases->fetchAll(PDO::FETCH_OBJ); But some texts are not showing completely So I have to change the value of group_concat_max_len. I did as follows: mysql_query("SET group_concat_max_len = 2048"); But using PDO not know how Can you not use $conn->query() ? $conn->query("SET group_concat_max_len = 2048"); 来源: https://stackoverflow.com/questions/18153293/set-group-concat-max-len-on-a-pdo-query

Set group_concat_max_len on a PDO query

拜拜、爱过 提交于 2019-12-01 15:32:46
问题 I have the following query: $cases = $conn->prepare("SELECT GROUP_CONCAT(text SEPARATOR '|') as texts, year FROM cases GROUP BY year ORDER BY ano DESC"); $cases->execute(); $cases_result = $cases->fetchAll(PDO::FETCH_OBJ); But some texts are not showing completely So I have to change the value of group_concat_max_len. I did as follows: mysql_query("SET group_concat_max_len = 2048"); But using PDO not know how 回答1: Can you not use $conn->query()? $conn->query("SET group_concat_max_len = 2048")

MySQL SELECT from multiple tables, multiple GROUP BY and group_concat?

限于喜欢 提交于 2019-12-01 04:38:33
问题 I have three tables which I want to query in MySQ. As follows: **Table: Leaderboard** Name | Score ------------ James | 1 Steve | 2 Dave | 5 **Table: Actions** Name | Action | Time ---------------------------- James | Ate an apple | 01:00 James | Kicked a dog | 02:00 Steve | Ate a dog | 03:00 Steve | Kicked a hen | 01:00 Dave | died | 02:00 **Table: Items** Name | Item | Time ---------------------------- James | Chainsaw | 01:00 James | Hammer | 01:05 James | Crowbar | 01:10 Steve | Hammer |

Accomplishing MYSQL's Group_Concat in SQL Server [duplicate]

拜拜、爱过 提交于 2019-12-01 04:25:46
This question already has an answer here: How to concatenate text from multiple rows into a single text string in SQL server? 47 answers I'm porting an application I originally wrote to run on Apache using PHP and a MySQL database. One of the queries used the MySQL functions of Concat_WS and Group_Concat to first concatenate a few different columns into one string, and then concatenate all items that were grouped together by the Group_By clause. As an example: ID Name Candy 1 John M&Ms 1 John KitKat The query: Select Group_Concat(Concat_WS('-',Name, Candy) Separator '00--00') as UserCandy From

Group_Concat in Concat not working with NULL values

大憨熊 提交于 2019-12-01 04:11:54
I have a table CREATE TABLE IF NOT EXISTS `dept` ( `did` int(11) NOT NULL, `dname` varchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `dept` (`did`, `dname`) VALUES (1, 'Hi'), (2, NULL), (3, 'Hello'); Then I have a query select group_concat(concat(did,"','",dname) separator '),(') as Result from dept It is producing result as 1','Hi'),('3','Hello Question: How can I get result from above query as 1','Hi'),('2','NULL'),('3','Hello It is missing the rows which have NULL values but I need to fetch all Link for SQL Fiddle Demo of question UPDATE: If I have more than one

GROUP_CONCAT() row count when grouping by a text field

孤人 提交于 2019-12-01 03:39:47
DROP TABLE IF EXISTS `table`; CREATE TABLE `table` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `table` VALUES ('1', 'Unpacked reserved sir offering bed judgment may and quitting speaking. Is do be improved raptures offering required in replying raillery. Stairs ladies friend by in mutual an no. Mr hence chief he cause. Whole no doors on hoped. Mile tell if help they ye full name. \r\n\r\nLadyship it daughter securing procured or am