Here is my query where I am getting list of all children categories for parent category which is 3
SELECT GROUP_CONCAT(lv SEPARATOR ',')
FROM (
SELECT @pv:=(
SELECT GROUP_CONCAT(id SEPARATOR ',')
FROM ad_category
WHERE is_active = 1
AND FIND_IN_SET(parent_id, @pv)
) AS lv
FROM ad_category
JOIN (SELECT @pv:=3)tmp
WHERE FIND_IN_SET(parent_id, @pv)
) a;
The above query is taking 7 sec time to getting 2100 id with ,
in string format.
I need the query to get results in millisecond. How I can optimized this query optimized query. Any help is nicely appreciable?
Here my category table format
///// MYSQL CATEGORY table
id name parent_id
1 shoes 0
2 blue shoes 1
3 men blue shoes 2
4 men blue shoe small 3
5 red shoes 1
6 men red shoes 5