I have a select statement with rows as table_Schema I need to merge the rows such that blogs with same row id are merged into a single row. I am trying to get either <author fname, author mname, author lname | coauthor fname coauthor lname> or a column as author co author Each blog can have multiple aut…
Tag: group-concat
MYSQL Select different records from same table
I am working on small school database and I need some help with selecting students that are only booked on different days in week 1 and week 2. My table structure is like below: I would like to get all the children that meet the following criteria: ONLY booked in week two (This is ChildId 2 and I can get
MySQL Query Returns Different Results
I’m having a strange problem with the following query: Sometimes I get zero, one, two or three results. I should always get three results. What could be causing this? Answer As pointed out by Solarflare, GROUP_CONCAT() could produce your team string in a random order, e.g. ‘Van Williams & Dere…
GROUP CONCAT and LEFT OUTER JOIN to split
I’m working with SQL Workbench. This is an example of the tables I have: I have not created this DB and can’t modify it. Each building corresponds to a site, so it contains a KEY to such site. Same with levels and buildings. I am trying to get this result the first two columns are easy, but I̵…
Grouping together results of multiple GROUP_CONCAT() with distinct values only
second attempt at this question with more detail. I am attempting to group the distinct values of multiple columns together for objects of the same name. I can use GROUP_CONCAT on each of the ‘Type’ columns, but I can’t merge them together to get a distinct set of values for each name Here i…
SQL Function inside of where clause to see if field is in concatenated list (from parameter)
I have these two lines ,SUM (CASE WHEN (DATEDIFF(DAY,Shopify_Ordered,Confirmed) >= 1)THEN 1 ELSE 0 END) OVER () Orders1DayNotShipped ,dbo.GROUP_CONCAT( (CASE WHEN (DATEDIFF(DAY,Shopify_Ordered,…
mysql – GROUP_CONCAT rows into a string
I have a following result set: req_id | p_id | ai_result | hash | sku 1 | 4 | Match | XAN | HOW 1 | 4 | Match | HXN | HOW 1 | 4 | Non Match | 123 | …
Multiple COALESCE in GROUP_CONCAT – is showing value if only first column isn’t null
Two table’s purchase and sales ‘s column date column has been concatenated as date row. GROUP_CONCAT(purchase.date,’,’,sales.date) AS date But both of them can be blank, according to data input. So …
Can we define a GROUP_CONCAT function in PostgreSQL?
I have several lines of SQL code for my legacy database with GROUP_CONCAT statements, as in: In PostgreSQL, I can do the same with: I would like to reuse the old SQL as much as possible. So I need to define a GROUP_CONCAT function that internally calls string_agg. Is this possible? EDIT: The linked question i…
Optimize GROUP_CONCAT in SQL on MySQL
Is there a way to get the following SQL optimized so it would run faster? I encountered the bottleneck are the GROUP_CONCAT’s but I couldn’t find a way by using an alternative or optimizing the query so it would run faster. At the moment the query needs about 3.2s on 2700 entries (mysql database 5…