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 = 369 
WHERE 
  cscart_products_categories.product_id IN (
    427, 408, 1971, 382, 418, 1959, 1930, 
    1960, 1961, 1931, 1529, 1465, 1932, 
    1962, 1933, 1935, 1958, 329, 439, 1969, 
    393, 394, 1929, 396, 1964, 1927, 1965, 
    440, 1966, 1928, 1973, 1968, 1963, 327, 
    1934, 2000, 2001, 385, 405, 413, 1970, 
    1937, 414, 389, 1972, 1974, 442, 1936, 
    326, 441, 322, 1957
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.04027

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "204.80"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "30.17"
      },
      "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": 30,
            "filtered": "32.80",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (427,408,1971,382,418,1959,1930,1960,1961,1931,1529,1465,1932,1962,1933,1935,1958,329,439,1969,393,394,1929,396,1964,1927,1965,440,1966,1928,1973,1968,1963,327,1934,2000,2001,385,405,413,1970,1937,414,389,1972,1974,442,1936,326,441,322,1957))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "6.03",
              "prefix_cost": "138.42",
              "data_read_per_join": "482"
            },
            "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": 30,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "30.17",
              "eval_cost": "6.03",
              "prefix_cost": "174.63",
              "data_read_per_join": "482"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
322 339,338,355,374,376,349M,378,341,350,345,357,375,354,370,369,342,372,352,358,373,353,351,344,356,377,371 0
326 395,373,396,353,362,351,356,377,394,361,371,380,385,359,355,381,363,374,376,384,386,389,349M,378,382,383,350,390,357,375,354,392,391,368,388,393,360,370,369,372,379,352,358 0
327 360,370,369,372,379,352,358,373,353,362,351,356,377,361,371,380,385,359,355,381,363,374,376,384,386,349M,378,382,383,350,357,375,354 0
329 357,375,354,339,370,369,372,352,358,373,353,338,351,356,377,371,355,374,376,349M,378,342,350 0
382 349,378,344,342,350,357,375,340,343,354,379,339,370,369,372,352,358,373,353,338,351,356,377,371,341,385,345,381,355,384,386,337M,347,382,374,383,376 0
385 337M,368,388,393,347,374,376,395,396,349,360,378,344,342,394,350,357,375,362,340,343,354,361,339,370,369,372,352,358,373,353,338,359,351,356,377,371,363,341,345,390,392,391,355 0
389 384,386,382,383,355,337M,347,374,376,349,378,344,342,379,350,357,380,375,340,343,354,339,370,369,372,352,358,373,385,353,338,381,351,356,377,371,341,345 0
393 381,351,356,377,371,341,345,384,386,382,383,355,337M,347,374,376,349,378,344,342,379,350,357,380,375,340,343,354,339,370,369,372,352,358,373,385,353,338 0
394 369,372,352,358,373,385,353,338,381,351,356,377,371,341,345,384,386,382,383,355,337M,347,374,376,349,378,344,342,379,350,357,380,375,340,343,354,339,370 0
396 340,343,354,370,339,369,372,352,358,373,353,338,351,356,377,371,341,345,355,337M,347,374,376,349,378,344,342,350,357,375 0
405 390,344,342,350,392,357,391,375,340,343,354,368,388,393,370,339,369,395,372,396,352,360,358,373,394,353,338,351,356,377,362,371,341,361,345,355,337M,347,359,374,376,363,349,378 0
408 374,376,349,378,344,342,350,357,385,375,381,340,343,354,370,339,369,384,386,372,352,358,382,373,383,353,338,351,356,377,371,341,345,379,355,337M,380,347 0
413 355,363,337M,374,376,349,378,344,342,368,350,357,375,340,343,354,360,370,339,369,372,352,362,358,373,361,353,338,351,356,377,371,341,345,359 0
414 371,341,345,359,355,363,337M,374,376,349,378,344,342,368,350,357,375,340,343,354,360,370,339,369,372,352,362,358,373,361,353,338,351,356,377 0
418 358,373,353,338,351,356,377,371,341,345,355,363,337M,374,376,349,378,344,342,350,357,375,340,343,354,370,339,369,372,352 0
427 379,370,339,369,372,380,352,347,358,373,353,338,351,356,377,371,341,345,385,381,355,337M,384,386,374,376,382,383,349,378,344,342,350,357,375,340,343,354 0
439 362,350,357,361,375,340,343,354,379,370,339,369,372,352,359,358,373,353,338,351,377,371,341,345,363,385,381,368,355,337M,384,386,360,374,376,382,383,349,378,344,342 0
440 376,390,362,361,375,392,391,388,393,370,369,372,359M,395,396,373,394,377,371,363,368,360,374 0
441 382,383,349,344,342,360,350,357,340,343,354,380,347,362,361,339,352,356,358,370,353,338,369,351,372,359,341,345,381,371,355,363,337M,384,368 0
442 363,378,384,368,374,376,382,383,360,379,375,380,362,361,373,370,369,372,385,359M,377,381,386,371 0
1465 355,337,381,386,371,363,349,378,384,344,342,368,374,390,350,376,382,357,383,392,340,343,354,391,347,360,379,388,393,339,375,380,352,356,395,362,358,396,361M,353,338,351,394,341,373,370,345,369,372,385,359,377 0
1529 370,345,369,372,385,359,377,355,337,381,386,371,363,349M,378,384,344,342,368,374,390,350,376,357,392,340,343,354,391,347,360,379,388,393,339,375,380,352,356,395,362,358,396,361,353,338,351,394,341,373 0
1927 361M,353,338,351,370,345,369,359,377,337,363,349,378,374,390,350,340,391,379,339,362,358 0
1928 339,362,361M,338,370,345,369,359,381,349,378,374,390,350,391,395,379 0
1929 391,379,373,339,338,377,345,369,337,359,381,363M,388,349,352,390,350 0
1930 349,352,390,395,350,341,353,351,391,362,379,361M,339,355,338,377,345,376,369,337,359,381,354,363,375,340,356,388 0
1931 340,388,349,372,385,390,395,350,353,391,362,371,379,361M,339,342,338,360,345,376,369,337,359,381,380,374,396,363 0
1932 359,381,394,352,388,349,390,350,391,384,362M,379,339,377,338,378,345,369 0
1933 374,345,369,396,363,359,381,340,394,341,372,352,386,388,370,349,355,390,350,361M,391,362,379,339,360,338,376,337 0
1934 360,356,338,358,337,374,345,369,396,363,373,359,381,340,394,395,372,352,344,370,349,355,384,390,350,342,361M,391,377,362,354,379,339 0
1935 391,362,379,380,339,376,360,338,337,374,345,369,363,359,381,340,394,395,388,372,352,344,349,393,384,390,350,342,361M 0
1936 378,377,375,384,390,350,361M,391,362,379,356,339,376,360,338,396,341,337,373,353,374,386,345,369,363,359,381,394,395,388,370,352,349 0
1937 352,342,354,349,378,377,375,384,390,350,380,361M,358,391,362,351,379,385,356,339,376,382,360,338,371,368,396,341,337,373,353,340,357,374,386,392,345,343,369,363,347,359,355,381,372,394,395,344,388,370,393 0
1957 370,352,349,377,361M,362,379,339,331,360,338,368,337,340,369,363,359,381 0
1958 369,388,363,359,381,370,352,349,377,361M,362,379,339,360,338,368,337,340 0
1959 360,338,368,337,340,369,363,359,381,350,370,352,349,377,361M,362,379,339 0
1960 379,339,360,338,368,337,340,378,369,363,359,381,370,352,349,377,361M,362 0
1961 361M,362,379,339,360,338,368,337,340,378,350,369,363,359,381,370,349,377 0
1962 349,377,361M,388,362,379,390,339,360,338,337,340,350,369,363,359,381,352,370 0
1963 370,349,377,361M,388,362,379,339,360,378,338,337,340,350,369,363,359,381,352 0
1964 369,363,359,381,370,349,377,361M,368,362,379,339,360,378,338,337,340 0
1965 337,340,352,369,363,359,381,370,349,377,361M,368,362,379,339,360,338 0
1966 360,338,337,340,352,369,363,359,381,370,349,377,361M,368,362,379,339 0
1968 362,379,339,360,338,337,340,352,369,363,359,381,370,349,361M,350 0
1969 368,361M,350,362,379,339,360,338,337,340,352,369,363,359,381,370,349 0
1970 349,368,361M,350,362,379,339,360,338,337,340,352,369,363,359,381,377,370 0
1971 381,377,370,349,368,361M,350,362,379,339,360,338,337,340,352,369,363,359 0
1972 340,352,369,363,359,381,370,349,368,361M,350,362,379,339,360,338,337 0
1973 360,338,337,340,352,377,369,363,359,381,370,349,368,361M,362,379,339 0
1974 362,379,339,360,338,337,340,352,369,363,359,381,370,350,349,368,361M 0
2000 362,338,391,390,369,363,396M,349 0
2001 349,362,338,391,390,369,363,396M 0