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.04770

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