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
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.
Comments