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
8
votes
1 answer

Strange duplicate behavior from GROUP_CONCAT of two LEFT JOINs of GROUP_BYs

Here is all my tables' structure and the query (please focus on the last query, appended below). As you see in the fiddle, here is the current output: +---------+-----------+-------+------------+--------------+ | user_id | user_name | score |…
Martin AJ
  • 6,261
  • 8
  • 53
  • 111
8
votes
3 answers

How to execute a query which is stored in a table column MySQL?

mysql> select * from CT; | CID | MID | REPORT_QUERY | | 1 | 1 | select * from emp; | | 2 | 2 | select * from student; | 2 rows in set (0.00 sec) I want to execute queries in REPORT_QUERY column. DELIMITER // CREATE…
8
votes
3 answers

New column in pandas - adding series to dataframe by applying a list groupby

Give the following df Id other concat 0 A z 1 1 A y 2 2 B x 3 3 B w 4 4 B v 5 5 B u 6 I want the result with new column with grouped values as list Id other concat …
chase
  • 3,592
  • 8
  • 37
  • 58
8
votes
2 answers

group_concat with multiple joins in MySQL

Database schema create table `questions` ( `id` int not null auto_increment, `title` varchar(45) not null, primary key (`id`)); create table `tags` ( `id` int not null auto_increment, `question_id` int not null, `name` varchar(45) not…
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
8
votes
3 answers

How to get distinct values on GROUP_CONCAT using Google Big Query

I'm trying to get distinct values when using GROUP_CONCAT in BigQuery. I'll recreate the situation using a simpler, static example: EDIT: I've modified the example to represent better my real situation: 2 columns with group_concat which needs to be…
Leonardo Naressi
  • 313
  • 4
  • 14
8
votes
1 answer

Set group_concat_max_len on a PDO query

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…
user2668863
  • 83
  • 1
  • 4
8
votes
3 answers

Group_Concat in Concat not working with NULL values

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…
Sami
  • 8,168
  • 9
  • 66
  • 99
8
votes
2 answers

Mysql return more than one row

I have this query. SELECT notes.id,enter.name as 'enter_name',step.title as 'flow status',notes.user_name as user_created,notes.created,notes.rel_client_id,td_doc_nr.value_string as 'document number',enter.enter_code, …
Oyeme
  • 11,088
  • 4
  • 42
  • 65
7
votes
2 answers

SELECT with GROUP_CONCAT, GROUP BY, HAVING

I Have table with odd_id and i want to select combinations for different ticket_id's. Here's my query: SELECT ticket_id, GROUP_CONCAT(odd_id) as oddsconcat FROM ticket_odds GROUP BY ticket_id And it gives me Following: '28',…
user474470
7
votes
1 answer

mysql join with multiple values in one column

I need to make a query that creates 3 columns that come from 2 tables which have the following relations: TABLE 1 has Column ID that relates to TABLE 2 with column ID2 In TABLE 1 there is a column called user In TABLE 2 there is a column called…
Luis Alvarado
  • 8,837
  • 12
  • 46
  • 60
7
votes
1 answer

mysql count items in group_concat

I am having a trouble with using GROUP_CONCAT in MySQL My tables g0 as follows: ID Age Sex ------------- 1 16 Male 2 18 Female 3 16 Male 4 18 Female 5 16 Male But I need the table to look like ID count 1,3,5 3 2,4 …
Mohd Zoubi
  • 186
  • 3
  • 16
7
votes
2 answers

How can I use GROUP_CONCAT in Rails?

I have the following query which I want to use with ActiveRecord so that it can be translated in native ORACLE based query on production server. Right now I am using SQLITe. select c.name,co.code,GROUP_CONCAT(c.name) AS GroupedName from countries…
Volatil3
  • 14,253
  • 38
  • 134
  • 263
7
votes
3 answers

SQL GROUP_CONCAT split in different columns

I searched a lot, but didn't find a proper solution to my problem. What do I want to do? I have 2 tables in MySQL: - Country - Currency (I join them together via CountryCurrency --> due to many to many relationship) See this for a working example:…
Bram Wijns
  • 199
  • 1
  • 2
  • 8
7
votes
1 answer

Accomplishing MYSQL's Group_Concat in SQL Server

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…
What have you tried
  • 11,018
  • 4
  • 31
  • 45
7
votes
6 answers

How to hack MySQL GROUP_CONCAT to fetch a limited number of rows?

I somehow need this feature,but MySQL doesn't support it at this moment. I'm using GROUP_CONCAT(CONCAT(...)) to generate a xml-like stuff. But when the size exceeds the limit,the xml is just broken! So I have to somehow make it only retrieve 5 rows…
Misier
  • 1,455
  • 4
  • 13
  • 15