I have the following query:
SELECT GROUP_CONCAT(p.name) AS names
FROM cte t
LEFT JOIN products p
ON p.tag_id = t.id
GROUP BY t.orig_id
HAVING SUM(t.id = 6) > 0;
It returns something like this:
+-------------------------------------+
| names |
+-------------------------------------+
| iPhone 14 Promax,Samsung Galaxy A55 |
+-------------------------------------+
But I want the following result:
+----+-------------------------------------+
| id | names |
+----+-------------------------------------+
| 2 | iPhone 14 Promax |
| 3 | Samsung Galaxy A55 |
+----+-------------------------------------+
Any idea how can I get that result?
Online Demo
1