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 = 352 
WHERE 
  cscart_products_categories.product_id IN (
    421, 427, 408, 1971, 382, 418, 1959, 1930, 
    400, 1960, 424, 381, 1529, 401, 1465, 
    1932, 1962, 1933, 1935, 1958, 428, 415, 
    391, 406, 329, 439, 390, 1969, 393, 394, 
    1929, 396, 397, 398, 399, 422, 434, 383, 
    412, 435, 419, 430, 324, 1965, 1966, 
    431, 432, 1973, 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, 1957
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.01678

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "247.61"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "49.63"
      },
      "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": 49,
            "filtered": "53.95",
            "index_condition": "(`eshopuga_upgr_4122`.`cscart_products_categories`.`product_id` in (421,427,408,1971,382,418,1959,1930,400,1960,424,381,1529,401,1465,1932,1962,1933,1935,1958,428,415,391,406,329,439,390,1969,393,394,1929,396,397,398,399,422,434,383,412,435,419,430,324,1965,1966,431,432,1973,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,1957))",
            "cost_info": {
              "read_cost": "92.00",
              "eval_cost": "9.93",
              "prefix_cost": "138.42",
              "data_read_per_join": "794"
            },
            "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": 49,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "49.63",
              "eval_cost": "9.93",
              "prefix_cost": "197.98",
              "data_read_per_join": "794"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

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