Using Mysql GROUP_CONCAT in JOIN Query

Bob

I have a string resulting like this :

'41,42,43,44,45,46,'

from this query :

SELECT 
    GROUP_CONCAT(lv
        SEPARATOR ',') as Id
FROM
    (SELECT 
        @pv:=(SELECT 
                    GROUP_CONCAT(Id
                            SEPARATOR ',')
                FROM
                    iot_zone
                WHERE
                    FIND_IN_SET(id_zone, @pv)) AS lv
    FROM
        iot_zone
    JOIN (SELECT @pv:=40) tmp) a;

I need to join this result to a query like :

SELECT T.* FROM T, T2
WHERE T.Id = T2.Id

where T2 is a table with the result of GROUP_CONCAT

41
42
43
44
45
46

Can you help me ?

Many thanks

Sergey Menshov

Try the following

CREATE TABLE T2(Id int);
INSERT T2(Id)VALUES(41),(42),(43);

SELECT *
FROM
  (
    SELECT '41,42,43,44,45,46,' Id
  ) T
JOIN T2 on CONCAT(',',T.Id) LIKE CONCAT('%,',T2.Id,',%')

I hope I understood your question correctly.

I found another variant with FIND_IN_SET - SELECT WHERE IN with GROUP_CONCAT as input

I think it'll be more useful

SELECT *
FROM
  (
    SELECT '41,42,43,44,45,46,' IdList
  ) T
JOIN T2 ON FIND_IN_SET(T2.Id,T.IdList)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysql JOIN with GROUP_CONCAT in a complex query

From Dev

mysql query join group_concat

From Dev

mysql request using join and group_concat

From Dev

mysql request using join and group_concat

From Dev

Using MYSQL GROUP_CONCAT with sub query

From Dev

Mysql query using IN with group_concat result

From Dev

Using MYSQL GROUP_CONCAT with sub query

From Dev

MySql duplicated values in a join using GROUP_CONCAT

From Dev

MySql duplicated values in a join using GROUP_CONCAT

From Dev

MySQL group_concat with join

From Dev

Mysql GROUP_CONCAT and IN query

From Dev

mySQL GROUP_CONCAT - Query

From Dev

Mysql with Group by + IF + Left Join + Group_Concat

From Dev

mysql inner join group_concat mysql

From Dev

join query with group_concat, duplicate values

From Dev

MySQL: update with join using GROUP_CONCAT: ERROR 1111 (HY000): Invalid use of group function

From Dev

Optimize MySQL query for group_concat function

From Dev

MySQL GROUP_CONCAT Query Excluding Records

From Dev

Mysql group_concat query gives error

From Dev

Select query with GROUP_CONCAT in mysql

From Dev

How to fix this query? Using GROUP_CONCAT

From Dev

Mysql group_concat for count in sub query using parent filed is not allowed

From Dev

Join and group concat mysql query not working as expected

From Dev

how to use select query in a Group_concat sub query in mysql

From Dev

MySQL: How to sort when using concat in group_concat?

From Dev

MySQL: How to sort when using concat in group_concat?

From Dev

Converting MySQL code to Access: GROUP_CONCAT and a triple JOIN

From Dev

Double results in GROUP_CONCAT with double JOIN in MySQL

From Dev

mysql self join with group_concat and without duplicates

Related Related

HotTag

Archive