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

ORDER BY not working with CONCAT statement in MySQL

For my project I have a strange requirement!! I am having three tables such as ATab, BTab, and CTab as followes CREATE TABLE IF NOT EXISTS `ATab` ( `id` int(8) unsigned NOT NULL AUTO_INCREMENT, `oid` int(8) unsigned NOT NULL, `type` int(1) unsigned…
Damodaran
  • 10,882
  • 10
  • 60
  • 81
3
votes
2 answers

sql group_concat and subquery

I have 2 mysql tables: car_model: id (int) (Primary Key) title (varchar) id_brand (int) FK to car_brand table car__car_model: - relation many to many id_model (int) id_advice_model (int) In car__car_model there are the…
programmer
  • 103
  • 3
  • 11
3
votes
1 answer

Group concat per row by getting all table results

For my search index I need to create an sql to get serval table results. For example, I have the following tables; tags (in this table I get all the tags) video_tags (in this table I get video_id's related to a tag id) videos (all videos) When I…
directory
  • 3,093
  • 8
  • 45
  • 85
3
votes
1 answer

Stata function equivalent to group_concat

I would like to group concatenate a categorical variable. Example: pat x 1 a 1 b 1 b 2 a 2 a The group concatenating should result in: pat y 1 a-b-b 2 a-a In Mysql this would be done using group_concat: SELECT pat, GROUP_CONCAT(x SEPARATOR '-')…
giordano
  • 2,954
  • 7
  • 35
  • 57
3
votes
4 answers

MySQL GROUP_CONCAT Assign incrementing value

I need to assign an incrementing value to each string from the concatenated row starting at 0 for each row in the result. Here's a simplified data sample: number|color 1 |red 1 |blue 1 |orange 2 |brown 3 |purple 3 …
jgc9876
  • 85
  • 8
3
votes
3 answers

Different delimiter in group concat

I have an sql query like this:- REPLACE( GROUP_CONCAT( IF( (timediff(delta_ts,creation_ts) > '03:00:00') && (priority='P5') ,bug_id,'') ),',,','' ) AS exceeded_bugs from bugs ...... The result I…
Monisha
  • 429
  • 2
  • 6
  • 22
3
votes
1 answer

Php and MySQL GROUP_CONCAT with separator comma and search where concat by comma

Is it that possible to select in Group_concat with separator comma and search where concat by comma Here My sample of mysql : products_attributes_id |products_id| options_id| options_values_id 39 | 31 | 3 | …
Jows
  • 877
  • 2
  • 11
  • 21
3
votes
2 answers

GROUP_CONCAT and LEFT_JOIN issue - Not all rows returned

Let's say my DB Scheme is as follows: T_PRODUCT id_product (int, primary) two entries: (id_product =1) , (id_product =2) T_USER id_user (int, primary) id_product (int, foreign key) name_user (varchar) two entries: (id_product=1,name_user='John')…
altermativ
  • 690
  • 1
  • 6
  • 20
3
votes
1 answer

insert data from multiple rows to one row mysql

Ok here's the thing. I need to insert multiple rows in one column from table A to one row in table B using MySql Here's an example of what im trying to achieve: Table A id | data 1 | name 2 | date 3 | more From table A, i need to select all the…
3
votes
1 answer

mysql row to column with group_concat and count?

i have 2 tables, users and follows. table follows has a column named status. I would like to count how many follows each user has grouping by the status. The query below returns a record for each status type for each user. SELECT users.name as…
user1736363
  • 69
  • 1
  • 8
3
votes
3 answers

Mysql group_concat with distinct values from another row

My first post here, hope I am following the posting guidelines right. If not, please do point out. My table structure (credit_notes) with some sample data looks like this: index | customer_id | user_id | doc_number | doc_date | amount |…
deadbeef
  • 41
  • 4
3
votes
1 answer

MySQL Lowercase Returned Value Or Entire Result

I have the below SQL query and it will return a group_name along with a list of departments for that group. I was able to lowercase the departments returned, but I can't figure out how to lowercase the group name as well. Also, instead of…
kittycat
  • 14,983
  • 9
  • 55
  • 80
3
votes
1 answer

Group Employee for each Department

I have a table Details DeptId EmpID ------- --------- 1 1 1 5 1 3 2 8 2 9 I want to group them like this: DeptId EmpIDs ------- ------- 1 1,5,3 2 …
aditya
  • 302
  • 3
  • 15
3
votes
1 answer

CSV formatted GROUP_CONCAT in MySQL

Let's say I have a Table A that I want to transform into Table B. The values in Table B should always be a CSV formated text with the same number of fields. First, I need to know what is the largest number of values that a given category handles…
kairos
  • 524
  • 4
  • 16
3
votes
3 answers

MySQL Group_Concat Distinct By Id

Is it possible to group_concat records by distinct Ids: GROUP_CONCAT(Column2 BY DISTINCT Column1) I need to get the values from column2 by distinct values from column1. Because there are repeating values in column 2, that's why I can't use distinct…
KaeL
  • 3,639
  • 2
  • 28
  • 56