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 (
    337, 335, 334, 329, 330, 331, 325, 319, 
    320, 321, 322, 323, 318, 317, 306, 307, 
    308, 309, 310, 311, 312, 313, 314, 315, 
    316, 303, 304, 305, 302, 301, 300, 298, 
    293, 292, 291, 290, 287, 278, 280, 282, 
    247, 248, 241, 244, 245, 246, 240, 6
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00116

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "35.20"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.63"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 86,
            "rows_produced_per_join": 3,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "19.95",
              "eval_cost": "0.69",
              "prefix_cost": "20.64",
              "data_read_per_join": "8K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`atulecarter_atul_demo1`.`cscart_categories`.`storefront_id` in (0,1)) and ((`atulecarter_atul_demo1`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`atulecarter_atul_demo1`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`atulecarter_atul_demo1`.`cscart_categories`.`usergroup_ids`)) and (`atulecarter_atul_demo1`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "atulecarter_atul_demo1.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 3,
            "rows_produced_per_join": 1,
            "filtered": "15.82",
            "index_condition": "(`atulecarter_atul_demo1`.`cscart_products_categories`.`product_id` in (337,335,334,329,330,331,325,319,320,321,322,323,318,317,306,307,308,309,310,311,312,313,314,315,316,303,304,305,302,301,300,298,293,292,291,290,287,278,280,282,247,248,241,244,245,246,240,6))",
            "cost_info": {
              "read_cost": "10.87",
              "eval_cost": "0.33",
              "prefix_cost": "33.57",
              "data_read_per_join": "26"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids
6 191M
240 165M
241 165M
244 168M
245 235M
246 199M
247 165M
248 248M,255
278 224M
280 224M
282 224M
287 224M
290 265M
291 265M
292 265M
293 265M
298 265M
300 265M
301 265M
302 265M
303 265M
304 265M
305 265M
306 265M
307 265M
308 265M
309 265M
310 265M
311 265M
312 265M
313 265M
314 265M
315 265M
316 265M
317 265M
318 265M
319 265M
320 265M
321 265M
322 265M
323 265M
325 224M
329 265M
330 265M
331 265M
334 265M
335 265M
337 265M