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, 
  product_position_source.position AS position 
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') 
  LEFT JOIN cscart_products_categories AS product_position_source ON cscart_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 372 
WHERE 
  cscart_products_categories.product_id IN (
    1, 228, 8, 9, 5290, 10, 8483, 2892, 71, 
    2896, 2902, 4, 2359, 1532, 2906, 5271, 
    6340, 8499, 8502, 5851, 8501, 4974, 
    5277, 2459, 5640, 5284, 5376, 5287, 
    5281, 5397, 4995, 5270, 2901, 5278, 
    5187, 5549, 5235, 1528, 2776, 2432, 
    2771, 4992, 5661, 2774, 5207, 2455, 
    5737, 6385, 5186, 1517, 5008, 5272, 
    4991, 2438, 5276, 8498, 5660, 7624, 
    8484, 8497, 5285, 5346, 2812, 5728, 
    7608, 5879, 2250, 8485, 1538, 5265, 
    8488, 8486, 8492, 2899, 5288, 8487, 
    5523, 7614, 5666, 6823
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00466

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "310.22"
    },
    "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": 355,
            "rows_produced_per_join": 355,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (1,228,8,9,5290,10,8483,2892,71,2896,2902,4,2359,1532,2906,5271,6340,8499,8502,5851,8501,4974,5277,2459,5640,5284,5376,5287,5281,5397,4995,5270,2901,5278,5187,5549,5235,1528,2776,2432,2771,4992,5661,2774,5207,2455,5737,6385,5186,1517,5008,5272,4991,2438,5276,8498,5660,7624,8484,8497,5285,5346,2812,5728,7608,5879,2250,8485,1538,5265,8488,8486,8492,2899,5288,8487,5523,7614,5666,6823))",
            "cost_info": {
              "read_cost": "144.26",
              "eval_cost": "35.50",
              "prefix_cost": "179.76",
              "data_read_per_join": "5K"
            },
            "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": 17,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "88.75",
              "eval_cost": "1.78",
              "prefix_cost": "304.01",
              "data_read_per_join": "55K"
            },
            "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')))"
          }
        },
        {
          "table": {
            "table_name": "product_position_source",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id",
              "product_id"
            ],
            "key_length": "6",
            "ref": [
              "const",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 17,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "4.44",
              "eval_cost": "1.78",
              "prefix_cost": "310.22",
              "data_read_per_join": "284"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1 174,166,372,453,454,190M 0
4 166,174,372,453,454,190M 0
8 166,174,372,453,454,190M 0
9 174,166,372,454,453,190M 0
10 174,166,372,454,453,190M 0
71 453,454,166,174,190M
228 453,454,372,174,166,190M 0
1517 454,453,372,174,166,190M 0
1528 453,454,372,174,166,190M 0
1532 454,453,372,174,166,190M 0
1538 454,453,372,174,166,190M 0
2250 435,372M 0
2359 329,455,453,372,337,174,166,527M 0
2432 372,174,166,453,454,190M 0
2438 454,453,174,372,166,190M 0
2455 454,453,372,166,174,190M 0
2459 372,166,453,454,174,190M 0
2771 372,463M 0
2774 461,372,464M 0
2776 372,461,462M 0
2812 527,329,455,453,372,174,166,337M 0
2892 372,384,459M 0
2896 384,372,459M 0
2899 372,384,460M 0
2901 372,384,460M 0
2902 372,384,460M 0
2906 466,372,467M 0
4974 372,552,556,553,250,554M 0
4991 552,554,553,372,250,556M 0
4992 552,553,554,250,372,556M 0
4995 552,553,554,372,250,556M 0
5008 561,555,557,552,553,372,250,563M 0
5186 372,250,557,555,562,553,552,560M 0
5187 557,555,250,372,562,553,552,560M 0
5207 372,250,555,557,552,553,563,561M 0
5235 372,551M 0
5265 372,250,563,557,555,553,552,561M 0
5270 250,372,563,557,555,553,552,561M 0
5271 250,372,563,557,555,553,552,561M 0
5272 250,372,563,557,555,553,552,561M 0
5276 250,372,563,557,555,553,552,561M 0
5277 250,372,563,557,555,553,552,561M 0
5278 250,372,563,557,555,553,552,561M 0
5281 250,372,563,557,555,553,552,561M 0
5284 400,372,563,557,555,553,552,561M 0
5285 250,372,563,557,555,553,552,561M 0
5287 372,250,563,557,555,553,552,561M 0
5288 250,372,563,557,555,553,552,561M 0
5290 250,372,563,557,555,553,552,561M 0
5346 554,553,250,372,552,556M 0
5376 372,250,553,552,554,556M 0
5397 372,250,553,554,552,556M 0
5523 466,372,573M 0
5549 553,250,552,554,372,556M 0
5640 555,553,250,560,557,552,372,562M 0
5660 372,587M 0
5661 372,587M 0
5666 372,587M 0
5728 461,372,462M 0
5737 461,372,462M 0
5851 372,583M 0
5879 466,372,579M 0
6340 566,372,595M 0
6385 372,583M 0
6823 554,556M
7608 190,454M
7614 454,190M
7624 190,454M
8483 454,166,372,453,174,190M 0
8484 453,174,454,166,372,190M 0
8485 453,174,454,166,372,190M 0
8486 174,372,454,166,453,190M 0
8487 166,453,174,372,454,190M 0
8488 166,453,174,372,454,190M 0
8492 174,454,166,453,372,190M 0
8497 174,454,372,166,453,190M 0
8498 372,166,453,174,454,190M 0
8499 174,454,166,453,372,190M 0
8501 372,453,166,174,454,190M 0
8502 372,174,454,453,166,190M 0