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.company_id = 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 = 361 
WHERE 
  cscart_products_categories.product_id IN (
    421, 443, 1971, 1959, 1930, 1960, 436, 
    438, 437, 1961, 1931, 381, 1529, 1465, 
    1962, 1933, 1935, 1958, 428, 406, 439, 
    390, 1969, 398, 1964, 434, 383, 1927, 
    435, 419, 403, 324, 1965, 440, 1966, 
    431, 1928, 1973, 1968, 1963
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00820

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "186.40"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "21.81"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 115,
            "rows_produced_per_join": 2,
            "filtered": "2.00",
            "cost_info": {
              "read_cost": "27.56",
              "eval_cost": "0.46",
              "prefix_cost": "28.02",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "company_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`eshopuga_upgr_4122`.`cscart_categories`.`company_id` = 1) and ((`eshopuga_upgr_4122`.`cscart_categories`.`usergroup_ids` = '') or find_in_set(0,`eshopuga_upgr_4122`.`cscart_categories`.`usergroup_ids`) or find_in_set(1,`eshopuga_upgr_4122`.`cscart_categories`.`usergroup_ids`)) and (`eshopuga_upgr_4122`.`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": [
              "eshopuga_upgr_4122.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 40,
            "rows_produced_per_join": 21,
            "filtered": "23.70",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,443,1971,1959,1930,1960,436,438,437,1961,1931,381,1529,1465,1962,1933,1935,1958,428,406,439,390,1969,398,1964,434,383,1927,435,419,403,324,1965,440,1966,431,1928,1973,1968,1963))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "4.36",
              "prefix_cost": "138.42",
              "data_read_per_join": "348"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "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",
              "eshopuga_upgr_4122.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 21,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "21.81",
              "eval_cost": "4.36",
              "prefix_cost": "164.59",
              "data_read_per_join": "348"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
324 359,356,388,361,351,368,360,354,357,392,340,393,362,352,358,391,390,394,396,355,363,353,338M,349,395,350 0
381 374,338,337M,349,350,371,344,359,370,341,343,356,361,351,339,376,384,360,354,357,340,362,352,342,383,385,358,372,373,347,355,363,345,380,382,378,386,353,379,381,375 0
383 386,353,381,375,374,338,337M,349,350,371,344,359,370,341,343,368,356,361,351,339,376,384,360,377,354,357,340,362,352,342,385,358,372,373,347,355,363,345,378 0
390 395,347,355,363,345,353,388,338,337M,349,350,344,359,392,341,343,368,393,356,361,351,339,391,360,390,394,396,354,357,340,362,352,342,358 0
398 362,352,342,358,395,347,355,389,363,345,353,388,338,337M,349,350,344,359,392,341,343,368,393,356,361,351,339,391,360,390,394,396,354,357,340 0
403 360,394,362,395,363,388,359M,392,368,393,361 0
406 390,396,354,361,357,340,352,342,360,394,358,362,347,355,345,353,395,363,338,337M,349,350,388,344,341,343,356,351,359,392,339,368,391,393 0
419 356,351,359,392,339,368,391,393,390,396,354,361,357,340,352,342,360,394,389,358,362,355,345,353,395,363,338,337M,349,350,388,344,341,343 0
421 350,388,344,341,343,356,351,359,392,339,368,391,393,390,396,354,361,357,340,352,342,360,394,358,362,355,345,353,395,363,338,337M,349 0
428 363,338,337M,349,350,388,344,341,343,356,351,359,392,339,368,391,393,390,396,354,361,347,357,340,352,342,360,394,358,362,355,345,353,395 0
431 355,345,353,395,363,338,337M,349,350,388,344,341,343,356,351,359,392,339,368,391,393,390,396,354,361,357,352,342,360,394,358,362 0
434 358,379,362,355,386,345,381,353,363,338,337M,349,350,344,341,343,356,384,351,347,359,383,339,340,368,354,361,357,385,352,342,360,380,382 0
435 361,385,352,360,380,382,379,362,395,386,381,363,388,349M,392,391,393,390,396,384,351,359,383,368,394 0
436 359M,368,361,360,362,363 0
437 359M,368,361,360,362,363 0
438 359M,368,361,360,362,363 0
439 351,357,373,383,342,363,378,358,375,385,352,382,355,374,345,379,371,353,370,386,359,381,368,338,337M,369,361,350,376,377,344,360,341,349,343,362,339,340,354,372,384 0
440 362,394,372,373,363,375,395,374,371,370,359M,388,368,369,361,376,377,360,392,391,393,390,396 0
443 360,362,363,359M,368,361 0
1465 377,368,392,339,340,391,393,361M,390,396,354,384,351,357,360,383,342,380,394,378,372,362,358,373,385,352,382,355,345,379,375,363,353,395,374,386,381,371,338,337,350,370,356,388,347,344,341,349,343,369,359,376 0
1529 347,344,341,349M,343,369,359,376,377,368,392,339,340,391,393,361,390,396,354,384,351,357,360,342,380,394,378,372,362,358,373,385,352,355,345,379,375,363,353,395,374,386,381,371,338,337,350,370,356,388 0
1927 338,337,350,370,349,369,359,377,339,340,391,361M,390,351,378,362,358,345,379,363,353,374 0
1928 374,338,350,370,349,369,359,339,391,361M,390,378,362,395,345,379,381 0
1930 363,353,395,345,356,379,381,388,341,337,376,338,350,354,377,340,349,369,359,351,339,391,361M,352,390,355,375,362 0
1931 371,362,363,353,395,374,345,379,381,388,337,396,376,360,338,350,342,380,372,340,349,369,385,359,339,391,361M,390 0
1933 339,391,361M,390,362,363,341,374,370,345,379,381,388,337,394,396,376,360,338,350,372,340,349,369,352,359,355,386 0
1935 340,349,369,352,359,339,391,361M,344,390,393,395,362,384,363,374,345,379,381,388,337,342,380,394,376,360,338,350,372 0
1958 338,340,349,369,352,359,339,368,361M,370,362,377,363,379,381,388,337,360 0
1959 337,350,360,338,340,349,369,352,359,339,368,361M,370,362,377,363,379,381 0
1960 363,379,381,337,360,338,340,349,369,352,359,339,368,361M,370,362,378,377 0
1961 370,362,378,377,363,350,379,381,337,360,338,340,349,369,359,339,368,361M 0
1962 370,362,377,363,350,390,379,381,337,360,338,352,340,349,369,359,388,339,361M 0
1963 359,388,339,361M,378,370,362,377,363,350,379,381,337,360,338,352,340,349,369 0
1964 340,349,369,359,339,361M,378,370,362,377,363,379,381,337,360,338,368 0
1965 360,338,368,340,349,369,359,339,361M,370,362,377,363,379,381,337,352 0
1966 379,381,337,352,360,338,368,340,349,369,359,339,361M,370,362,377,363 0
1968 362,363,379,381,337,352,360,338,340,349,369,359,350,339,361M,370 0
1969 370,362,363,379,381,337,368,352,360,338,340,349,369,359,350,339,361M 0
1971 339,377,361M,370,362,363,379,381,337,368,352,360,338,340,349,369,359,350 0
1973 340,349,369,359,339,377,361M,370,362,363,379,381,337,368,352,360,338 0