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
7
votes
2 answers

Select first and last row from group_concat when grouping sortable days

Referring to my previous questions about the group concat Mysql again, group by and display rest of rows i need to get first and last day from that query for example row 3 from 8,9,10 to first collumn 8, last collumn 10 row 5 from…
breq
  • 24,412
  • 26
  • 65
  • 106
7
votes
1 answer

GROUP_CONCAT with JOINLEFT in Zend Db Select

Assuming that I have 2 tables articles id title 1 Article 1 2 Article 2 Images id article_id image 1 1 a.png 2 1 b.png 3 …
Nấm Lùn
  • 1,277
  • 6
  • 28
  • 48
7
votes
1 answer

Add an inner join to mySQL GROUP_CONCAT statement

Problem: I have a GROUP_CONCAT query that is working as intended, except I'd like to make the concat a joined answer, not the raw ID field. Current query: SELECT user.user_id, user.user, GROUP_CONCAT(user_roles.roleID separator ', ') roles FROM…
Laurence
  • 58,936
  • 21
  • 171
  • 212
6
votes
4 answers

Using ORDER BY clause inside GROUP_CONCAT function in SQLite

I don't think that I can use ORDER BY clause inside the GROUP_CONCAT function. Does anyone know a tricky way to accomplish this behavior in SQLite? I saw this question before. But I have a complex query . My statement looks like this: SELECT …
confucius
  • 13,127
  • 10
  • 47
  • 66
6
votes
1 answer

How to use UNION and GROUP_CONCAT together

I have a problem with the correct syntax to use UNION and GROUP_CONCAT in this situation: I have 4 tables: base: Is the main table with a lot of columns. mm: Is a mm table that points to the next two tables using a 'tablenames' field. t1 and t2…
Memochipan
  • 3,405
  • 5
  • 35
  • 60
6
votes
2 answers

How to use GROUP_CONCAT with Zend Framework?

Assume that I have a table : students ______________________________________________________ |id | name | school | class | ______________________________________________________ | 1 | John | ABC | C1 …
Nấm Lùn
  • 1,277
  • 6
  • 28
  • 48
6
votes
2 answers

MySQL how to select into JSON ARRAY

in MySQL 5.7 we have the JSON_ARRAY object. I'd like to perform something similar to a SELECT GROUP_CONCAT(field) but with the results into a JSON_ARRAY. My current query is: SELECT GROUP_CONCAT(name) FROM users; result: john,michael,sofia I'd…
Stefano Giacone
  • 2,016
  • 3
  • 27
  • 50
6
votes
3 answers

MySQL GROUP_CONCAT doesn't return all results

i've used GROUP_CONCAT to get results splitted by comma (,), but when i saw, the GRUP_CONCAT returned only 205 splitted numbers, but in the database there's 2448 results (different aid). Here is my query: SELECT GROUP_CONCAT(`aid`) As favoriti FROM…
Ultrazz008
  • 1,678
  • 1
  • 13
  • 26
6
votes
2 answers

mysql GROUP_CONCAT

I want to list all users with their corropsonding user class. Here are simplified versions of my tables CREATE TABLE users ( user_id INT NOT NULL AUTO_INCREMENT, user_class VARCHAR(100), PRIMARY KEY (user_id) ); INSERT INTO users VALUES …
bigstylee
  • 1,240
  • 1
  • 12
  • 22
6
votes
2 answers

mysql multiple group_concat order preservation

let's say I have a table mytable: select * from mytable: +------+------+------+ | a | b | c | +------+------+------+ | 1 | 1 | a | | 1 | 2 | b | +------+------+------+ I want to group both the columns b and c with…
ryskajakub
  • 6,351
  • 8
  • 45
  • 75
6
votes
1 answer

MySQL performance: Single query using GROUP_CONCAT, or two separate queries?

I have a MySQL database in which each user has an account, and each account can have multiple permissions. My ultimate goal is to end up with the account's username, and a comma-delimited list of permissions ids. There are two ways I can accomplish…
Warren Benedetto
  • 2,478
  • 2
  • 22
  • 25
6
votes
1 answer

table joins with multiple group_concat

I have a problem regarding joining tables with group_concat. Here are the details. table_orders: item_cd order_id descs quantity status seq_no 1 100 coca-cola 2 A 232 2 …
6
votes
1 answer

GROUP_CONCAT return NULL if any value is NULL

How can I make GROUPT_CONCAT return NULL if any column is NULL? Here is a test table: CREATE TABLE gc ( a INT(11) NOT NULL, b VARCHAR(1) DEFAULT NULL ); INSERT INTO gc (a, b) VALUES (1, 'a'), (1, 'b'), (2, 'c'), (2, NULL), (3, 'e'); And my…
Petah
  • 45,477
  • 28
  • 157
  • 213
6
votes
1 answer

MySql GROUP_CONCAT failing when exporting from phpmyadmin

When I test a query using group_concat it works fine and outputs the proper comma-delimited list in the row. However, when I then click "Export" at the bottom of the resultset, I get an error saying #1630 - FUNCTION .group_concat does…
devios1
  • 36,899
  • 45
  • 162
  • 260
5
votes
3 answers

Concatenate column values for rows with the same values (of different columns)

SQL Server 2005 I have a table which returns ID name prop value -------------------------- 1 one Prop1 a 1 one Prop1 b 1 one Prop2 c 2 two Prop1 d 2 two Prop2 e How can I run a select on it to…
Omar
  • 39,496
  • 45
  • 145
  • 213