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, 327, 1934, 
    385, 405, 413, 1970, 1937, 433, 414, 
    407, 402, 1972, 388, 1974, 442, 1936, 
    416, 326, 441, 1957
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01262

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "217.31"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "35.86"
      },
      "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": 35,
            "filtered": "38.97",
            "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,327,1934,385,405,413,1970,1937,433,414,407,402,1972,388,1974,442,1936,416,326,441,1957))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "7.17",
              "prefix_cost": "138.42",
              "data_read_per_join": "573"
            },
            "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": 35,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "35.86",
              "eval_cost": "7.17",
              "prefix_cost": "181.45",
              "data_read_per_join": "573"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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