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 = 350 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 1971, 382, 418, 1959, 1930, 
    400, 424, 1961, 1931, 381, 1529, 1465, 
    1932, 1962, 1933, 1935, 428, 415, 391, 
    406, 329, 439, 390, 1969, 393, 394, 1929, 
    396, 397, 398, 399, 422, 434, 383, 412, 
    1927, 419, 430, 324, 431, 432, 1928, 
    429, 1968, 384, 1963, 327, 1934, 395, 
    420, 385, 405, 410, 413, 1970, 417, 1937, 
    414, 425, 407, 323, 389, 402, 1972, 388, 
    426, 409, 1974, 404, 325, 1936, 387, 
    386, 416, 326, 441, 322
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01979

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "244.75"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "48.33"
      },
      "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": 48,
            "filtered": "52.53",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,1971,382,418,1959,1930,400,424,1961,1931,381,1529,1465,1932,1962,1933,1935,428,415,391,406,329,439,390,1969,393,394,1929,396,397,398,399,422,434,383,412,1927,419,430,324,431,432,1928,429,1968,384,1963,327,1934,395,420,385,405,410,413,1970,417,1937,414,425,407,323,389,402,1972,388,426,409,1974,404,325,1936,387,386,416,326,441,322))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "9.67",
              "prefix_cost": "138.42",
              "data_read_per_join": "773"
            },
            "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": 48,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "48.33",
              "eval_cost": "9.67",
              "prefix_cost": "196.42",
              "data_read_per_join": "773"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
322 353,352,342,338,345,341,373,376,354,372,357,378,351,374,370,375,339,356,371,369,358,355,344,349M,350,377 0
323 355,349M,350,353,352,354,357,351,356,358 0
324 356,362,363,358,391,368,359,361,355,388,395,349,350,338M,392,353,352,340,354,357,390,360,351,394,396,393 0
325 356,358,355,349M,350,353,352,357,351 0
326 357,386,385,351,393,377,362,363,389,391,368,359,361,356,382,388,395,358,381,373,376,392,355,372,384,349M,350,378,353,352,374,380,370,354,375,371,369,390,360,394,379,396,383 0
327 371,369,360,379,383,357,386,385,351,377,362,363,359,361,356,382,358,381,373,376,355,372,384,349M,350,378,353,352,374,380,370,354,375 0
329 353,352,374,370,354,375,371,369,342,357,351,338,377,356,358,373,376,355,372,339,349M,350,378 0
381 349,380,350,378,344,347,353,352,360,374,370,354,379,375,383,345,371,341,386,385,342,343,357,362,363,351,340,338,359,361,382,381,356,384,337M,358,373,376,355,372,339 0
382 337M,358,373,376,355,372,339,349,350,378,344,347,369,353,352,374,370,354,379,375,383,345,371,341,386,385,342,343,377,357,351,340,338,382,381,356,384 0
383 381,356,384,337M,358,373,376,355,372,339,349,360,350,378,344,368,347,353,352,374,370,354,375,345,362,371,341,363,386,385,342,343,359,377,361,357,351,340,338 0
384 351,340,338,356,337M,358,355,339,349,350,344,347,353,352,354,345,341,342,343,357 0
385 390,342,343,394,357,396,351,340,338,393,373,376,391,356,372,337M,358,369,388,360,395,378,355,368,392,339,349,374,350,370,344,375,347,362,371,353,352,363,354,359,377,361,345,341 0
386 354,345,341,342,343,357,351,340,338,356,337M,358,355,339,349,350,344,347,353,352 0
387 344,347,353,352,354,345,341,342,343,357,351,340,338,356,337M,358,355,339,349,350 0
388 355,359,361,339,349,350,381,344,380,347,353,352,384,354,345,341,342,343,357,379,383,351,340,360,338,368,386,385,356,337M,358,362,382,363 0
389 385,356,377,337M,358,382,355,339,349,350,381,344,380,347,353,352,384,354,373,376,345,372,341,369,342,343,378,357,379,383,351,340,374,338,370,375,371,386 0
390 338,362,363,390,356,359,361,394,337M,358,396,355,339,393,349,350,344,391,347,353,352,388,354,395,345,341,392,342,360,343,357,368,351,340 0
391 343,357,351,340,338,356,337M,358,355,339,349,350,344,347,353,352,354,345,341,342 0
393 370,345,341,375,371,342,386,343,385,357,377,382,351,340,338,381,356,380,337M,358,384,355,373,376,339,372,349,350,369,344,378,347,353,379,352,383,354,374 0
394 378,347,353,379,352,383,354,374,370,345,341,375,371,342,386,343,385,357,377,382,351,340,338,381,356,380,337M,358,384,355,373,376,339,372,349,350,369,344 0
395 339,349,350,344,347,353,352,354,345,341,342,343,357,351,340,338,356,337M,358,355 0
396 376,337M,358,372,369,355,378,339,349,350,344,374,370,347,353,352,375,371,354,345,341,377,342,343,357,351,340,338,356,373 0
397 356,337M,358,355,339,349,350,344,347,353,352,354,345,341,342,343,357,351,340,338 0
398 368,351,340,338,362,356,363,390,337M,358,359,361,389,394,396,355,339,349,350,393,344,347,353,352,391,354,388,345,395,341,342,392,343,360,357 0
399 342,343,357,351,340,338,356,337M,358,355,339,349,350,344,347,353,352,354,345,341 0
400 354,345,341,342,343,357,351,340,338,356,337M,358,355,339,349,350,344,347,353,352 0
402 349,350,344,392,347,360,353,352,368,354,345,341,342,343,362,357,363,390,351,340,359,361,394,338,396,393,356,337M,358,391,355,388,339,395 0
404 355,339,349,350,344,347,353,352,354,345,341,342,343,357,351,340,338,356,337M,358 0
405 391,356,388,337M,358,373,395,376,372,355,392,369,339,360,349,378,350,368,344,347,374,353,352,370,354,375,362,371,345,363,341,390,342,359,377,361,394,343,396,357,351,340,338,393 0
406 338,393,391,356,388,337M,358,395,355,392,339,360,349,350,368,344,347,353,352,354,362,345,363,341,390,342,359,361,394,343,396,357,351,340 0
407 359,361,394,343,396,357,351,340,338,379,393,383,391,356,388,337M,358,386,395,385,355,392,382,339,360,349,350,368,344,347,353,352,381,380,354,362,384,345,363,341,390,342 0
408 354,384,345,341,342,343,357,373,351,340,376,338,372,379,383,369,378,356,337M,358,374,386,370,385,355,375,371,382,339,349,350,344,377,347,353,352,381,380 0
409 347,353,352,354,345,341,342,343,357,351,340,356,337M,358,355,339,349,350,344 0
410 355,339,349,350,344,353,352,354,345,341,342,338,343,357,351,340,356,337M,358 0
412 356,337M,358,355,347,339,349,350,344,353,352,354,345,341,342,338,343,357,351,340 0
413 377,362,363,359,356,361,337M,358,355,339,349,350,373,344,376,372,353,352,369,354,378,345,341,360,374,342,370,338,343,368,357,375,371,351,340 0
414 357,375,371,351,340,377,362,363,359,356,361,337M,358,355,339,349,350,373,344,376,372,353,352,369,354,378,345,341,360,374,342,370,338,343,368 0
415 341,342,338,343,357,351,340,356,337M,358,355,339,349,350,344,353,352,354,345 0
416 353,352,360,354,390,368,345,394,341,396,342,338,343,357,362,393,363,351,340,359,361,391,388,395,356,337M,358,392,355,339,349,350,344 0
417 349,350,344,353,352,354,345,341,342,338,343,357,351,340,356,337M,358,355,339 0
418 337M,358,374,355,370,339,375,349,371,350,344,377,353,352,354,345,341,363,342,338,343,357,351,340,373,376,372,369,356,378 0
419 356,337M,358,360,355,390,368,339,394,349,350,396,344,353,352,362,393,389,354,345,359,361,391,341,363,342,388,338,343,395,357,351,392,340 0
420 351,340,356,337M,358,355,339,349,350,344,353,352,354,345,341,342,338,343,357 0
421 392,342,338,343,357,351,340,360,356,390,368,337M,358,394,396,355,339,349,362,350,393,344,359,361,353,352,391,363,354,388,345,395,341 0
422 354,345,341,342,338,343,357,351,340,356,337M,358,355,339,349,350,344,353,352 0
424 344,353,352,354,345,341,342,347,338,343,357,351,340,356,337M,358,355,339,349,350 0
425 355,339,349,350,344,353,352,354,345,341,342,347,338,343,357,351,340,356,337M,358 0
426 356,337M,358,378,381,355,384,374,339,370,349,350,375,344,371,353,352,377,354,379,383,345,341,342,338,343,357,386,385,351,340,382,373,376,372 0
427 369,382,373,376,372,380,356,337M,358,378,381,355,384,374,339,370,349,350,375,344,371,353,352,377,354,379,347,383,345,341,342,338,343,357,386,385,351,340 0
428 338,343,363,357,388,395,351,340,392,356,337M,358,355,360,339,390,349,368,350,394,344,396,353,352,354,362,393,347,345,341,359,361,391,342 0
429 345,341,342,338,343,357,351,340,356,337M,358,355,339,349,350,344,353,352,354 0
430 353,352,354,345,341,342,338,343,357,351,340,356,337M,358,355,339,349,350,344 0
431 339,349,350,359,361,391,344,363,353,352,388,395,354,345,392,341,342,338,343,357,351,360,390,368,394,356,396,337M,358,355,362,393 0
432 337M,358,355,339,349,350,344,353,352,354,345,341,342,340,338,343,357,351,356,347 0
434 386,385,356,362,347,337M,358,382,359,361,355,380,363,339,349,350,381,344,353,352,384,354,345,341,342,340,338,343,357,379,360,383,351,368 0
439 360,383,351,368,369,373,386,376,385,372,362,337M,358,382,359,378,361,355,363,339,349,374,350,370,381,344,375,371,353,352,384,354,377,345,341,342,340,338,343,357,379 0
441 342,340,338,343,357,360,383,351,368,356,347,369,372,362,380,337M,358,382,359,361,355,363,339,349,350,370,381,344,371,353,352,384,354,345,341 0
1465 354,345,379,393,341,342,340,338,343,391,357,360,383,388,351,373,368,386,395,376,385,356,347,392,369,378,372,362,380,337,358,382,374,359,361M,355,375,363,339,349,350,370,381,390,344,377,394,371,353,352,384,396 0
1529 349M,350,370,381,390,344,377,394,371,353,352,384,396,354,345,379,393,341,342,340,338,343,391,357,360,388,351,373,368,386,395,376,385,356,347,392,369,378,372,362,380,337,358,374,359,361,355,375,363,339 0
1927 374,359,361M,363,339,349,350,370,390,377,353,345,379,340,338,391,351,369,378,362,337,358 0
1928 378,362,374,359,361M,381,339,349,350,370,390,345,379,395,338,391,369 0
1929 337,369,363M,352,359,381,377,339,349,350,390,388,373,345,379,338,391 0
1930 338,391,355,375,362,337,369,361M,354,363,353,352,341,359,381,377,339,349,350,390,340,376,356,388,351,395,345,379 0
1931 395,345,379,338,391,371,396,374,362,337,369,342,361M,363,353,360,359,381,385,339,349,350,390,340,376,372,380,388 0
1932 388,378,345,379,394,384,338,391,362M,369,352,377,359,381,339,349,350,390 0
1933 376,339,372,349,350,390,355,388,345,379,394,396,374,338,370,391,337,341,361M,362,386,363,369,352,360,359,381,340 0
1934 359,358,381,340,395,344,339,372,349,350,390,355,384,345,354,379,394,396,374,342,338,370,391,337,361M,373,362,377,363,356,369,352,360 0
1935 362,363,369,380,352,360,376,359,381,340,395,344,339,372,349,350,388,390,393,384,345,379,394,374,342,338,391,337,361M 0
1936 373,377,337,356,361M,362,363,369,352,360,375,378,376,359,381,395,339,349,350,388,390,353,384,396,341,370,345,379,386,394,374,338,391 0
1937 379,386,394,374,338,391,373,377,337,356,380,358,361M,362,363,369,352,360,375,371,340,378,376,344,355,372,343,359,357,381,393,395,339,354,368,349,350,388,390,347,392,382,385,353,384,396,341,342,370,351,345 0
1959 370,379,338,377,337,361M,362,363,369,352,360,340,359,381,339,368,349,350 0
1961 368,349,350,370,379,338,377,337,361M,362,378,363,369,360,340,359,381,339 0
1962 359,381,339,349,350,370,379,338,377,337,352,361M,362,363,369,360,388,390,340 0
1963 369,360,388,340,359,381,339,349,350,370,379,338,378,377,337,352,361M,362,363 0
1968 337,352,361M,362,363,369,360,340,359,381,339,349,350,370,379,338 0
1969 338,337,368,352,361M,362,363,369,360,340,359,381,339,349,350,370,379 0
1970 370,379,338,337,368,352,361M,362,363,369,360,340,359,381,339,349,350,377 0
1971 377,370,379,338,337,368,352,361M,362,363,369,360,340,359,381,339,349,350 0
1972 359,381,339,349,350,370,379,338,337,368,352,361M,362,363,369,360,340 0
1974 340,359,381,339,349,350,370,379,338,337,368,352,361M,362,363,369,360 0