SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
WHERE 
  cscart_products_categories.product_id IN (
    2702, 2703, 2704, 2705, 2706, 2708, 2709, 
    2710, 2714, 2715, 2716, 2717, 2719, 
    2728, 2723, 2724, 2725, 2726, 2729, 
    2730, 2731, 2732, 2739, 2740, 2741, 
    2742, 2743, 2744, 2745, 2746, 2747, 
    2749, 2750, 2751, 2752, 2753, 2754, 
    2755, 2756, 2757, 2761, 2762, 2763, 
    2764, 2768, 2767, 2760, 3164, 3165, 
    2737, 3255
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00240

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "118.36"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 132,
            "rows_produced_per_join": 132,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (2702,2703,2704,2705,2706,2708,2709,2710,2714,2715,2716,2717,2719,2728,2723,2724,2725,2726,2729,2730,2731,2732,2739,2740,2741,2742,2743,2744,2745,2746,2747,2749,2750,2751,2752,2753,2754,2755,2756,2757,2761,2762,2763,2764,2768,2767,2760,3164,3165,2737,3255))",
            "cost_info": {
              "read_cost": "58.96",
              "eval_cost": "13.20",
              "prefix_cost": "72.16",
              "data_read_per_join": "2K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 6,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "33.00",
              "eval_cost": "0.66",
              "prefix_cost": "118.36",
              "data_read_per_join": "20K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
2702 423,424,450,166M
2703 423,424,450,166M
2704 329,166,457M
2705 329,166,457M
2706 329,166,457M
2708 329,166,347M
2709 329,166,347M
2710 329,166,347M
2714 166,329,399,524M
2715 329,399,166,524M
2716 329,399,166,524M
2717 399,329,166,524M
2719 423,424,450,166M
2723 329,166,457M
2724 329,166,457M
2725 329,166,457M
2726 329,166,457M
2728 423,424,450,166M
2729 329,166,344M
2730 329,166,344M
2731 329,166,344M
2732 329,166,344M
2737 423,424,451,166M
2739 329,166,457M
2740 329,166,457M
2741 329,166,457M
2742 329,166,457M
2743 329,166,457M
2744 329,166,457M
2745 329,166,457M
2746 166,329,344M
2747 329,166,344M
2749 329,166,344M
2750 329,166,344M
2751 329,166,344M
2752 329,166,344M
2753 329,166,344M
2754 329,166,344M
2755 329,166,344M
2756 329,166,344M
2757 329,166,344M
2760 329,166,344M
2761 329,166,457M
2762 329,166,457M
2763 329,166,457M
2764 329,166,457M
2767 329,166,344M
2768 329,166,344M
3164 329,166,344M
3165 329,166,344M
3255 423,424,451,166M