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
5
votes
3 answers

GROUP_CONCAT change GROUP BY order

I have a VIEW (lots of joins) that outputs data ordered by a date ASC. Works as expected. OUTPUT similar to: ID date tag1 other_data 1 25-03-2011 blue fff <= 1 26-03-2011 red ggg 1 27-03-2011 pink yyy 2 25-03-2011 …
cmancre
  • 1,061
  • 3
  • 11
  • 23
5
votes
1 answer

Postgres aggregate alias for group_concat using string_agg

I know that postgres does not have group_concat, but I want to emulate it for strings by using string_agg (or any other way that works). I need to have the function called group_concat because of an inability to change legacy code. How can I do…
soandos
  • 4,978
  • 13
  • 62
  • 96
5
votes
5 answers

Sorting in group_concat

Data: id uid type 1 20 A 2 20 B 3 20 A 4 6 A 5 1 A 6 3 A 7 6 A 8 1 B Scenario: I want to group by type and sort it by id. I am using group by to group the uid. Current…
Shaharyar
  • 12,254
  • 4
  • 46
  • 66
5
votes
4 answers

Spark: group concat equivalent in scala rdd

I have following DataFrame: |-----id-------|----value------|-----desc------| | 1 | v1 | d1 | | 1 | v2 | d2 | | 2 | v21 | d21 | | …
Silverrose
  • 160
  • 4
  • 18
5
votes
1 answer

GROUP_CONCAT and Longtext

I need to combine two text fields in the MySQL Database table into One, So I have used the Following SQL script to do it. Table: tbl_newsitems Combine: Need to combine the text in the 'ni_text' with the same 'news_id' Table Layout: Code used to…
lbo
  • 51
  • 1
  • 2
5
votes
1 answer

SQL left join and group_concat returns duplicate data

I am trying to return data from 3 different tables with 2 left joins. All tables return multiple rows. Here is my statement: SELECT s.*, GROUP_CONCAT(sp.photo) AS photos, GROUP_CONCAT(st.name) AS tags FROM sites s LEFT JOIN sites_photos sp ON…
user2381011
  • 351
  • 6
  • 21
5
votes
1 answer

SQL: Get Products from a category but also must be in another set of categories

I am currently stuck in a situation. The scenario is this. I have products who may be associated with multiple categories. The data structure is shown below: Products Table: product_id name 1 Lemon 2 Kiwis 3 …
5
votes
1 answer

REGEXP to match a group string within another group list regardless of the order - SQL

Here is the scenario. How to utilize REGEXP to simulate IN operator yet to match all values in left side within right side regardless of the string order in either side. Also ANSI SQL solution can be achieved using left join and sub…
bonCodigo
  • 14,268
  • 1
  • 48
  • 91
5
votes
1 answer

GROUP_CONCAT in MySQL - how do I include distinct values?

I have two tables which I query with UNION ALL - one for Android and one for iPhone. Each table has its own device field ("android" or "iphone"). I use GROUP_CONCAT(DISTINCT `device` ORDER BY `device` SEPARATOR ', ') AS `device` a few times, each…
Uri
  • 2,992
  • 8
  • 43
  • 86
5
votes
1 answer

Mysql query only select rows with unique result within GROUP_CONCAT

Is there a way to select only the rows that have an other result than the row previous selected? In one of my tables I store advertisement data, that’s one row per advertisement. I also store in an other table the prices for rental per dag, week,…
Jilco Tigchelaar
  • 2,065
  • 8
  • 31
  • 51
5
votes
2 answers

CommunicationsException: Communications link failure

I used java to query some records from Mysql. But in some querys of one duration, i meet a problem which make query failed, but in others , it query successful. The error message is next: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:…
zhouzuan2k
  • 157
  • 2
  • 8
5
votes
1 answer

MySQL GROUP_CONCAT multiple fields

I'm probably having a no-brain moment. I want to return a series of numbers using GROUP_CONCAT from two fields in my database. I have done this so far using the following: SELECT t_id, CONCAT(GROUP_CONCAT(DISTINCT…
Pandy Legend
  • 1,102
  • 3
  • 15
  • 29
5
votes
2 answers

Using php to return GROUP_CONCAT('column x') values

I am trying to use PHP to return SQL values into an HTML table. I am able to get every column to populate without a problem except for the last column, "GROUP _ CONCAT (provision_id)." Relevant code:
Adam
  • 405
  • 1
  • 5
  • 22
5
votes
1 answer

MySQL group_concat in subquery returns more than one row

I have the query, below, which should work. But, MySQL is giving me the error message Subquery returns more than one row SELECT e.episode_pk, (SELECT GROUP_CONCAT(d.fulldescription separator ', ') FROM episode_rhythm er JOIN…
user1469297
  • 101
  • 1
  • 2
  • 4
5
votes
3 answers

MySQL list users and their groups

In MySql database I have table user user_id | user_name --------+---------- 1 | Joe 2 | Anna 3 | Max Table group group_id | group_name ---------+---------- 1 | Red 2 | Blue 3 | Green Table…
Goldie
  • 1,570
  • 5
  • 21
  • 33