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 = 7336 
WHERE 
  cscart_products_categories.product_id IN (
    98737, 98750, 98751, 98752, 98753, 98754, 
    98755, 98756, 98757, 99509, 99510, 
    99513, 99514, 99517, 99518, 99653, 
    99654, 99655, 99656, 99657, 99658, 
    99659, 99660, 99661, 99662, 99663, 
    99664, 99665, 99666, 99667, 99668, 
    100504, 100505, 100506, 100507, 100508, 
    100509, 100510, 100511, 100512, 100513, 
    100514, 100515, 100516, 100517, 100518, 
    100519, 100520, 100521, 100522, 100523, 
    100524, 100525, 100526, 100527, 100528, 
    100529, 100530, 100531, 100532, 100533, 
    100534, 100535, 100642, 100644, 100646, 
    100648, 100789, 100790, 100791, 100792, 
    100793, 100794, 100795, 100796, 100797, 
    100798, 100799, 100800, 100801, 100802, 
    100803, 100804, 100805, 100806, 100807, 
    100808, 100809, 100810, 100811, 100812, 
    100813, 100814, 100815, 100816, 100817
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01622

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "133.66"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "8.83"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 208,
            "rows_produced_per_join": 8,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "20.72",
              "eval_cost": "0.83",
              "prefix_cost": "21.55",
              "data_read_per_join": "21K"
            },
            "used_columns": [
              "category_id",
              "usergroup_ids",
              "status",
              "storefront_id"
            ],
            "attached_condition": "((`nuie_scalesta_net`.`cscart_categories`.`storefront_id` in (0,1)) and ((`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`nuie_scalesta_net`.`cscart_categories`.`usergroup_ids`))) and (`nuie_scalesta_net`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "link_type",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "nuie_scalesta_net.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 117,
            "rows_produced_per_join": 8,
            "filtered": "0.90",
            "cost_info": {
              "read_cost": "2.33",
              "eval_cost": "0.88",
              "prefix_cost": "121.75",
              "data_read_per_join": "141"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (98737,98750,98751,98752,98753,98754,98755,98756,98757,99509,99510,99513,99514,99517,99518,99653,99654,99655,99656,99657,99658,99659,99660,99661,99662,99663,99664,99665,99666,99667,99668,100504,100505,100506,100507,100508,100509,100510,100511,100512,100513,100514,100515,100516,100517,100518,100519,100520,100521,100522,100523,100524,100525,100526,100527,100528,100529,100530,100531,100532,100533,100534,100535,100642,100644,100646,100648,100789,100790,100791,100792,100793,100794,100795,100796,100797,100798,100799,100800,100801,100802,100803,100804,100805,100806,100807,100808,100809,100810,100811,100812,100813,100814,100815,100816,100817))"
          }
        },
        {
          "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",
              "nuie_scalesta_net.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 8,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "2.21",
              "eval_cost": "0.88",
              "prefix_cost": "124.84",
              "data_read_per_join": "141"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
98737 7217M,7337
98750 7217M,7337
98751 7217M,7337
98752 7217M,7337
98753 7217M,7337
98754 7217M,7337
98755 7217M,7337
98756 7217M,7337
98757 7217M,7337
99509 7219M,7313,7338
99510 7219M,7313,7338
99513 7219M,7313,7338
99514 7219M,7313,7338
99517 7219M,7313,7338
99518 7219M,7313,7338
99653 7217M,7337
99654 7217M,7337
99655 7217M,7337
99656 7217M,7337
99657 7217M,7337
99658 7217M,7337
99659 7217M,7337
99660 7217M,7337
99661 7217M,7337
99662 7217M,7337
99663 7217M,7337
99664 7217M,7337
99665 7217M,7337
99666 7217M,7337
99667 7217M,7337
99668 7217M,7337
100504 7217M,7337
100505 7217M,7337
100506 7217M,7337
100507 7217M,7337
100508 7217M,7337
100509 7217M,7337
100510 7217M,7337
100511 7217M,7337
100512 7217M,7337
100513 7217M,7337
100514 7217M,7337
100515 7217M,7337
100516 7217M,7337
100517 7217M,7337
100518 7217M,7337
100519 7217M,7337
100520 7217M,7337
100521 7217M,7337
100522 7217M,7337
100523 7217M,7337
100524 7217M,7337
100525 7217M,7337
100526 7217M,7337
100527 7217M,7337
100528 7217M,7337
100529 7217M,7337
100530 7217M,7337
100531 7217M,7337
100532 7217M,7337
100533 7217M,7337
100534 7217M,7337
100535 7217M,7337
100642 7217M,7337
100644 7217M,7337
100646 7217M,7337
100648 7217M,7337
100789 7219M,7313,7338
100790 7219M,7313,7338
100791 7219M,7313,7338
100792 7219M,7313,7338
100793 7219M,7313,7338
100794 7219M,7313,7338
100795 7219M,7313,7338
100796 7219M,7313,7338
100797 7219M,7313,7338
100798 7219M,7313,7338
100799 7219M,7313,7338
100800 7219M,7313,7338
100801 7219M,7313,7338
100802 7219M,7313,7338
100803 7219M,7313,7338
100804 7219M,7313,7338
100805 7219M,7313,7338
100806 7219M,7313,7338
100807 7219M,7313,7338
100808 7219M,7313,7338
100809 7219M,7313,7338
100810 7219M,7313,7338
100811 7219M,7313,7338
100812 7219M,7313,7338
100813 7219M,7313,7338
100814 7219M,7313,7338
100815 7219M,7313,7338
100816 7219M,7313,7338
100817 7219M,7313,7338