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

MYSQL WHERE field IN GROUP_CONCAT()

I have a couple of tables and each one has a many to many relationship, Lets say 'parents' 'Name', 'email', 'chid_id' 'Chris Pan', 'chris@email.com', 1 'Jane Pan', 'chris@email.com', 2 'Sally Jenkins', 'sally@email.com',…
MrPHP
  • 932
  • 2
  • 7
  • 19
2
votes
1 answer

Double GROUP_CONCAT with MySQL 5.6

I've got a query that bugs my mind right now. Here's my basic query : SELECT e.id AS `equipment.id`, t.id AS `task.id`, ttr.tags_id AS `tag.id` FROM equipment e LEFT JOIN task t ON t.equipment = e.id INNER JOIN task_tag_relationship ttr ON…
2
votes
1 answer

MySQL: select the first item returned by GROUP_CONCAT function

I have a group_concat which returns all the strings from one column. The strings can be variable length. How can I select the first string returned by the group_concat (where 'first' is defined by a group_concat ordering clause)? Here is a…
spiderplant0
  • 3,872
  • 12
  • 52
  • 91
2
votes
1 answer

How to quote values of single column using group_concat and concat, distinct

I need to use group_concat to build a list of comma separated values but I need the values to be quoted inside single quote. How to do this? The query which I have written doesn't work for me. I have values inside column like this: userid (column) …
Anonymous
  • 1,074
  • 3
  • 13
  • 37
2
votes
2 answers

group concat a field based on 2 same data in another field

Given this table, +----+------------------+-----------+----------+ | id | Doctor name | firsttime | lasttime | +----+------------------+-----------+----------+ | 1 | Dr. Abdurahman | 12:00:00 | 21:00:00 | | 2 | Dr. Sultan Hamid | 12:00:00 …
eric anthony
  • 73
  • 1
  • 9
2
votes
1 answer

Concatenate non empty CONCAT_GROUP to parent column in MySQL

I need to get the list of categories from store_cat, with the child COUNT from store_item (amount of products) and GROUP_CONCAT from store_cat_attributes (list of attributes). The thing is, using CONCAT function I need to attach the GROUP_CONCAT…
Andres SK
  • 10,779
  • 25
  • 90
  • 152
2
votes
5 answers

Using MS SQL Server 2005, how can I consolidate detail records into a single comma separated list

BACKGROUND:**I am running **MS2005. I have a MASTER table (ID, MDESC) and a DETAIL table (MID, DID, DDESC) with data as follows 1 MASTER_1 2 MASTER_2 1 L1 DETAIL_M1_L1 1 L2 DETAIL_M1_L2 1 L3 DETAIL_M1_L3 2 L1 DETAIL_M2_L1 2 L2 DETAIL_M2_L2 If I…
Noah
  • 15,080
  • 13
  • 104
  • 148
2
votes
3 answers

How To Use MySQL Group Concat

I have following Table | id | a | b | c | ------------------- | 1 | x | y | r | | 2 | x | y | q | | 3 | x | y | f | Result should be | a | b | c | ------------- | x | y | r,q,f | Tried with select a, b, group_concat(c) from table; but it…
Fr34k
  • 31
  • 1
2
votes
2 answers

string slicing in php or mysql substring_index

Output of following query has to be sliced. GROUP_CONCAT(DISTINCT subject.id, '-', subject.en_title ORDER BY subject.id) AS sub, Output is 3-Math 4-Science I am Using PHP substr $sub=substr(strstr($row['sub'], '-'), 1); so result would…
Dipak
  • 931
  • 14
  • 33
2
votes
1 answer

Incomplete output after concatenation and escaping characters

I have a string with concatenated values done on MySQL as below: CONCAT("[\"",GROUP_CONCAT(DISTINCT(concat_ws("=>",val_1, val_2,val_3)) ORDER BY val_4 DESC SEPARATOR "\",\""),"\"]") I have noticed that the output of each row seems incomplete, from…
UgoL
  • 839
  • 2
  • 13
  • 37
2
votes
5 answers

MySQL: Replace null with 0 in GROUP_CONCAT

I have a table called trx trx_year trx_month Product number_of_trx 2018 4 A 100 2018 5 A 300 2018 3 A 500 2018 1 A 200 2018 2 A 150 2018 …
Eru
  • 51
  • 8
2
votes
1 answer

listagg: remove adjacent duplicates

I have timestamped data and want to create a list from one column, with adjacent duplicates (but not all duplicates) collapsed into one. For example, given the following data: '2001-01-01 00:00:01' 'a' '2001-01-01 00:00:02' 'a' '2001-01-01 00:00:03'…
2
votes
1 answer

mysql GROUP_CONCAT(query)

I'm trying to run a query that looks like: SELECT GROUP_CONCAT(vehicles.id) FROM vehicles WHERE …
Jeff78
  • 23
  • 1
  • 4
2
votes
1 answer

SQLITE group_concat pairing values from two columns

I have a table like this: id key value 244574 16 999 244574 18 999 244574 54 174 214808 16 662 214808 17 808 214808 33 1 214808 60 2 214809 16 902 214809 17 1103 214809 33 …
Andreas B
  • 107
  • 10
2
votes
2 answers

Mysql - GROUP_CONCAT - Control order of other / merged columns

Given a table like this: id number anotherNumber 1 1 10 2 1 20 3 2 20 4 2 10 5 3 10 If I run the query: Select *, GROUP_CONCAT(number) FROM docs GROUP BY number I will…
Björn
  • 12,587
  • 12
  • 51
  • 70