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 = 7148 
WHERE 
  cscart_products_categories.product_id IN (
    96688, 96689, 96690, 96691, 96692, 96694, 
    96695, 96696, 96697, 96708, 96718, 
    96719, 96720, 96724, 96734, 96735, 
    96738, 96739, 96743, 96746, 96747, 
    96749, 96751, 96758, 96759, 96764, 
    96775, 96778, 96779, 96780, 96789, 
    96790, 96791, 96839, 96840, 96841, 
    96918, 96919, 96985, 96986, 96987, 
    96988, 96989, 96990, 96991, 96992, 
    96993, 96994, 96995, 96996, 96997, 
    96998, 96999, 97000, 97001, 97002, 
    97003, 97004, 97005, 97006, 97007, 
    97008, 97009, 97010, 97083, 97219, 
    97220, 97221, 97222, 97223, 97224, 
    97225, 97226, 97227, 97567, 97570, 
    97573, 97574, 97575, 97576, 97577, 
    97578, 97579, 97580, 97581, 97582, 
    97583, 97584, 97585, 97586, 97682, 
    97683, 97684, 97685, 97686, 97687
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00544

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "135.34"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "10.07"
      },
      "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": 10,
            "filtered": "1.03",
            "cost_info": {
              "read_cost": "2.33",
              "eval_cost": "1.01",
              "prefix_cost": "121.75",
              "data_read_per_join": "161"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ],
            "attached_condition": "(`nuie_scalesta_net`.`cscart_products_categories`.`product_id` in (96688,96689,96690,96691,96692,96694,96695,96696,96697,96708,96718,96719,96720,96724,96734,96735,96738,96739,96743,96746,96747,96749,96751,96758,96759,96764,96775,96778,96779,96780,96789,96790,96791,96839,96840,96841,96918,96919,96985,96986,96987,96988,96989,96990,96991,96992,96993,96994,96995,96996,96997,96998,96999,97000,97001,97002,97003,97004,97005,97006,97007,97008,97009,97010,97083,97219,97220,97221,97222,97223,97224,97225,97226,97227,97567,97570,97573,97574,97575,97576,97577,97578,97579,97580,97581,97582,97583,97584,97585,97586,97682,97683,97684,97685,97686,97687))"
          }
        },
        {
          "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": 10,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "2.52",
              "eval_cost": "1.01",
              "prefix_cost": "125.27",
              "data_read_per_join": "161"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
96688 7219M,7313,7338
96689 7219M,7313,7338
96690 7219M,7313,7338
96691 7219M,7313,7338
96692 7219M,7313,7338
96694 7157M,7341,7342,7343
96695 7263M
96696 7263M
96697 7263M
96708 7151M,7301
96718 7151M,7301
96719 7151M,7301
96720 7151M,7301
96724 7151M,7301
96734 7151M,7301
96735 7151M,7301
96738 7151M,7301
96739 7161M,7303
96743 7151M,7301
96746 7162M
96747 7162M
96749 7160M,7305
96751 7162M
96758 7151M,7301
96759 7151M,7301
96764 7151M,7301
96775 7151M,7301
96778 7225M,7226
96779 7225M,7226
96780 7225M,7226
96789 7160M,7305
96790 7160M,7305
96791 7225M,7226
96839 7225M,7226
96840 7225M,7226
96841 7167M,7183,7283
96918 7167M,7183,7283
96919 7167M,7183,7283
96985 7161M,7303
96986 7161M,7303
96987 7161M,7303
96988 7161M,7303
96989 7161M,7303
96990 7161M,7303
96991 7161M,7303
96992 7161M,7303
96993 7161M,7303
96994 7161M,7303
96995 7161M,7303
96996 7161M,7303
96997 7161M,7303
96998 7167M,7183,7283
96999 7161M,7303
97000 7161M,7303
97001 7161M,7303
97002 7161M,7303
97003 7161M,7303
97004 7161M,7303
97005 7161M,7303
97006 7161M,7303
97007 7161M,7303
97008 7161M,7303
97009 7161M,7303
97010 7161M,7303
97083 7157M,7341,7342,7343
97219 7157M,7341,7342,7343
97220 7157M,7341,7342,7343
97221 7157M,7341,7342,7343
97222 7157M,7341,7342,7343
97223 7157M,7341,7342,7343
97224 7157M,7341,7342,7343
97225 7157M,7341,7342,7343
97226 7157M,7341,7342,7343
97227 7157M,7341,7342,7343
97567 7157M,7341,7342,7343
97570 7157M,7341,7342,7343
97573 7157M,7341,7342,7343
97574 7208M,7241,7309,7346
97575 7208M,7241,7309,7346
97576 7157M,7341,7342,7343
97577 7157M,7341,7342,7343
97578 7157M,7341,7342,7343
97579 7157M,7341,7342,7343
97580 7157M,7341,7342,7343
97581 7247M,7265
97582 7157M,7341,7342,7343
97583 7157M,7341,7342,7343
97584 7157M,7341,7342,7343
97585 7157M,7341,7342,7343
97586 7157M,7341,7342,7343
97682 7208M,7241,7309,7346
97683 7208M,7241,7309,7346
97684 7208M,7241,7309,7346
97685 7208M,7241,7309,7346
97686 7208M,7241,7309,7346
97687 7208M,7241,7309,7346