Questions tagged [group-concat]

a function which returns a string representation of the concatenated, non-NULL values of a group

GROUP_CONCAT() or group_concat() is a function which returns a string representation of the concatenated, non-NULL values of a group.

This function is available in a variety of relational databases, including MySQL, SQLite, and MariaDB.

Resources

Related Tags

1334 questions
2
votes
1 answer

Pandas isin() output to string and general code optimisation

I am just starting to use python to do some analysis of data at work, so I could really use some help here :) I have a df with African countries and a bunch of indicators and another df with dimensions representing groupings, and if a country is in…
Tytire Recubans
  • 967
  • 10
  • 27
2
votes
3 answers

MYSQL select top 5 of a count from table that is grouped by user

I apologize in advance as I may not be describing my problem properly. I am trying to write a query that takes the top 5 most popular chosen_user_items per user and concatenating the top rows per user into a comma separated string via group_concat…
klye_g
  • 1,242
  • 6
  • 31
  • 54
2
votes
0 answers

MYSQL - How to convert a string resulting from GROUP_CONCAT function into a digit

I have been stuck for a while with this query and was wondering if anyone here knows what I may be doing wrong. The problem I'm facing is that the following query sends me a 0 instead of a -5 and if I remove the "CAST" function, I get -05, so it…
2
votes
0 answers

CakePHP 2.X - Set MySQL GROUP_CONCAT_MAX_LEN

I found a nice way to retrieve quickly data I need using MySQL's group_concat awesomeness. However, I sometimes have long strings of data to retrieve. WHich should not be a problem if you just increase the GROUP_CONCAT_MAX_LEN variable. I am able…
2
votes
2 answers

How to use ConcatRelated() on a many-to-many relationship

As a personal education experiment, I am building a database for an imaginary animal shelter. I am quite new to SQL and databases in general. Task: Finding all the owners of a pet in an animal shelter database. I have three tables: Pets, Owners, and…
Somatic
  • 193
  • 7
2
votes
1 answer

In SQLite, will multiple colums order the same way with group_concat?

I have a table like this: title id name manager.....1......bob manager.....2......tim manager.....3.....suzy worker.....4.....john And I'm doing a query: select title, group_concat(id), group_concat(name) group by title I get the…
sqlfused
  • 21
  • 3
2
votes
1 answer

How to correctly format quotation marks and double quotes in mysql query

I'm currently using PDO connection for perform some mysql queries and since I use the command $conn->prepare("HERE THE QUERY") I want to know how to format characters like quotes and double quotes. When I have cases like this…
UgoL
  • 839
  • 2
  • 13
  • 37
2
votes
2 answers

GROUP_CONCAT() like function to return fields that don't match?

I have three tables in my database, for the purposes of discussion let's say they are: USERS ----- user_id user_name ROLES ----- role_id role USER_ROLES ---------- user_role_id user_id role_id I can easily use GROUP_CONCAT() to return a comma…
Memento Lorry
  • 165
  • 1
  • 6
2
votes
1 answer

PHP MySQL GROUP_CONCAT Limit

I couldn't find wether this was possible so, is there any option to limit a GROUP_CONCAT in MySQL-function? E.g.: GROUP_CONCAT(ColName ORDER BY ColName DESC LIMIT 5) I don't want to use a subquery since this will seriously slow down the…
TVA van Hesteren
  • 1,031
  • 3
  • 20
  • 47
2
votes
2 answers

Problem with explode() in PHP

I'm having a problem with my explode function in PHP. I'm pulling a string from the database as follows: column_name 0,2000,0,3000,1000,7000,1000,0,0,0 After pulling this into an object called $recordset i'm using the explode function to make…
Jasdeep Singh
  • 3,276
  • 4
  • 28
  • 47
2
votes
1 answer

How to do a subquery in doctrine and get the result hydrated to an object?

I want to do a somewhat complex query in doctrine, namely an inner join with a subquery with a group_concat. See the query in plain SQL: SELECT * FROM kinderen k INNER JOIN ( SELECT i.kindid, GROUP_CONCAT(DISTINCT a.periode) as periodes FROM…
chrizzler
  • 82
  • 2
  • 9
2
votes
1 answer

Group_Concat in Crosstab

With a table like: Name Event Time Steve Start 19:53 Steve Event1 19:51 Steve Stop 19:45 Steve Start 18:13 Steve Event2 18:01 Steve Event1 17:51 Steve Stop 17:45 Bob Start 19:47 Bob Event2 19:31 Bob …
DHHJ
  • 103
  • 1
  • 12
2
votes
1 answer

mysql group concat into multiple fields

I have a recipe table, called recipes. There is the IDRecipe field and other parameters of the recipe except the categories. Categories are multi dimensional, so I have another table that connects one to many with one recipe. It is called category…
Jerry2
  • 2,955
  • 5
  • 30
  • 39
2
votes
0 answers

How to group concat on this result set in mssql

How to modify and apply concatination on the following result This is the first table: DECLARE @item_tbl TABLE ( ItemId INT,Title NVARCHAR(20)) INSERT INTO @item_tbl VALUES (1,'Title 1'),(2,'Title 2') ,(3,'Title 3'),(4,'Title 4'),(5,'Title 5') This…
Dheeraj Sharma
  • 709
  • 1
  • 6
  • 17
2
votes
1 answer

Weird result for GROUP_CONCAT on subquery

I am having a weird behavior when using GROUP_CONCAT on subquery. Here is my query : SELECT name, GROUP_CONCAT(DISTINCT (id) SEPARATOR "-") AS id FROM ( (SELECT "APN" AS name, …
user6050469
  • 177
  • 11