group-concat

How to GROUP_CONCAT where there are null values in MYSQL will fields from LEFT JOIN?

这一生的挚爱 提交于 2019-12-11 18:05:52
问题 This is related to my previous example question submitted here. I have the following sql query : SELECT listings.*, region.REGION_ID, #GROUP_CONCAT(region.REGION_ID) AS GROUP_IDs, ...... ...... INNER JOIN schedule ON schedule.SCHEDULE_ID = listings.LISTING_SCHEDULE_ID LEFT JOIN listing_region ON listing_region.LIST_REGION_LISTING_ID = listings.LISTING_ID ...... ...... WHERE listings.LISTING_ID IN (SELECT LISTING_ID FROM listings WHERE .......... The result is as follows : I get multiple

How to GROUP_CONCAT where there are null values in MYSQL?

送分小仙女□ 提交于 2019-12-11 15:08:33
问题 I have a long query that returns multiple values for a primary key (from a LEFT join). For example : (only showing two fields, but there about 10 fields) LotID Size 1 A 1 B 1 C 2 null 3 B 4 A 4 B When I use GROUP_CONACT, it returns as follows : LotID Size 1 A,B,C 3 B 4 A,B But what I actually want is : LotID Size 1 A,B,C 2 null 3 B 4 A,B I tried using GROUP_CONCAT(CONCAT_WS(',', IFNULL(Size,''))) AS Sizes, It returns : LotID Sizes 1 A,B,C,,, 3 B,, 4 A,B,, It does not return LotID=2, also

MYSQl - Count of elements inside Group_Concat

百般思念 提交于 2019-12-11 15:07:14
问题 I'm quite new to MYSQL and would need a little help in the group_concat statement. I have the below table Seller Merchant CustomerID S1 M1 C1 S1 M1 C1 S1 M1 C2 S1 M1 C3 S1 M1 C4 S2 M2 C5 S2 M2 C6 S3 M3 C6 For the combination of same seller and merchant, all the items which has different customerIDs along with the count of how many times it is repeated. I'm able to derive count of unique customer IDS using group_concat but not able to get the count. SELECT * , LENGTH(CUSTIDS) - LENGTH(REPLACE

Mysql working with comma separated list - Junction table

久未见 提交于 2019-12-11 10:39:35
问题 I have a Junction table with ProductID and Accessory column: TABLE1 ProductID Accessory 1 2 1 3 2 1 2 4 2 5 3 4 1 5 2 It means that for the ProductID 2, it has the Accessory ProductIDs 1,4 and 5 ... and i have THE TABLE 2 below which look like this THE GRP and ProductID is already provided, we need to fetch the accesories. TABLE2 GRP ProductID accessories a 2 b 3 c 1 d 4 e 5 so actually if using UPDATE it would be like this TABLE2 UPDATE table2 t2 set t2.accessories = (SELECT GROUP_CONCAT

mySQL >> Very Slow Query with CONCAT, GROUP_CONCAT and multiple JOINS (100 sec for 63 records)

a 夏天 提交于 2019-12-11 07:00:46
问题 I am using the following query: SELECT *, GROUP_CONCAT(distinct t_name order by t_id separator ', ') 'Topics', GROUP_CONCAT(distinct ch_title order by ch_id separator ', ') 'Chapters', GROUP_CONCAT(distinct cs_code order by cs_id separator ', ') 'ContentStandards', GROUP_CONCAT(distinct c_name order by c_id separator ', ') 'Categories', GROUP_CONCAT(distinct s_name order by s_id separator ', ') 'SchoolSubjects' FROM ( SELECT r.res_id, r.res_status, r.res_type, r.res_category, r.res_title, r

MySQL group by with left join

£可爱£侵袭症+ 提交于 2019-12-11 06:37:28
问题 I am trying to do a very complex query (at least extremely complex for me not for YOU :) ) I have users and comments table. SQL Fiddle: http://sqlfiddle.com/#!9/b1f845/2 select user_id, status_id from comments where user_id in (2,3); +---------+-----------+ | user_id | status_id | +---------+-----------+ | 2 | 10 | | 2 | 10 | | 2 | 10 | | 2 | 7 | | 2 | 7 | | 2 | 10 | | 3 | 9 | | 2 | 9 | | 2 | 6 | +---------+-----------+ If I use select user_id, status_id from comments where user_id in (2,3)

GROUP_CONCAT in Vertica

不羁的心 提交于 2019-12-10 21:41:56
问题 Suppose we have data something like this: date | campaign | raw | unq ------------+----------+-----+----- 2016-06-01 | camp1 | 5 | 1 2016-06-01 | camp2 | 10 | 1 2016-06-01 | camp3 | 15 | 2 2016-06-02 | camp4 | 5 | 3 2016-06-02 | camp1 | 5 | 1 I need to group it in such a way as to obtain the following result: date | campaigns | raw | unq ------------+---------------------+----- +----- 2016-06-01 | camp1, camp2, camp3 | 30 | 4 2016-06-02 | camp4, camp1 | 10 | 4 Mysql for these purposes has a

Limit results on an GROUP_CONCAT() or INNER JOIN

百般思念 提交于 2019-12-10 20:44:06
问题 I've perused extensively the other threads talking about limits on group_concat() and inner joins but haven't found my answer, so I guess I'll go ahead and ask it: I'm developing an existing photo community site. I want to retrieve members who have their birthday on a given day (today) and then retrieve each member's 5 most highly rated photos. But I also only want the 10 "most favorite" birthday members (ie with the highest favorite count). Here's what I have: SELECT users.user_id, users

new line separator doesn't work for group_concat function

ε祈祈猫儿з 提交于 2019-12-10 15:43:17
问题 I have a string (name lastname,name2 lastname2...) with values from a database table and I want to display it like: name lastname name2 lastname2.. I use group_concat function it works for commma separators but I need new line separator. group_concat(concat_ws(' ',users.firstname, users.lastname) SEPARATOR '<br>') as contacts_name 回答1: Try this : "\r\n" with double quotes, not simple 来源: https://stackoverflow.com/questions/17875870/new-line-separator-doesnt-work-for-group-concat-function

Search GROUP_CONCAT using LIKE

社会主义新天地 提交于 2019-12-10 14:16:59
问题 I have an SQL query that uses GROUP_CONCAT to get all people attached to a certain order. Is there a way I can search inside the GROUP_CONCAT field? SELECT orders.orderID, GROUP_CONCAT(contacts.firstName, " ", contacts.lastName) AS attachedContacts FROM (orders) JOIN contacts ON orders.contactID=contacts.contactID GROUP BY orders.orderID ORDER BY orders.orderID DESC I want to add something like WHERE attachedContacts LIKE '%Eric%' , to only list orders with 'Eric' attached, but still include