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.storefront_id IN (0, 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 = 423 
WHERE 
  cscart_products_categories.product_id IN (
    6151, 
    5696, 
    2698, 
    5721, 
    5621, 
    5724, 
    3605, 
    5944, 
    4951, 
    5830, 
    2340, 
    5887, 
    3354, 
    3155, 
    3834, 
    2737, 
    3308, 
    5892, 
    3306, 
    5848, 
    3397, 
    2352, 
    2431, 
    5934, 
    3841, 
    5114, 
    2339, 
    3212, 
    3389, 
    2924, 
    1626, 
    3350, 
    4163, 
    3392, 
    6098, 
    5811, 
    3390, 
    4934, 
    2862, 
    5719, 
    4960, 
    5706, 
    5720, 
    4933, 
    5850, 
    5821, 
    2922, 
    5849, 
    5828, 
    5703, 
    5832, 
    5824, 
    5798, 
    3603, 
    2693, 
    3928, 
    2338, 
    5826, 
    5801, 
    5864, 
    5829, 
    3301, 
    5852, 
    4894, 
    3660, 
    5928, 
    5822, 
    5847, 
    5854, 
    5896, 
    2341, 
    5794, 
    2702, 
    3147, 
    6099, 
    3828, 
    5898, 
    5788, 
    5932, 
    3649, 
    3520, 
    3529, 
    4962, 
    1668, 
    3146, 
    4958, 
    4942, 
    3809, 
    8586, 
    3518, 
    3148, 
    3918, 
    8372, 
    3215, 
    3213, 
    2222, 
    3400, 
    5691, 
    5687, 
    3733, 
    3552, 
    2805, 
    3232, 
    4915, 
    6025, 
    3149, 
    3416, 
    3157, 
    3589, 
    5791, 
    3845, 
    3150, 
    2481, 
    3822, 
    4976, 
    3115, 
    3740, 
    3123, 
    2228, 
    3743, 
    3112, 
    3944, 
    3664, 
    3126, 
    2230, 
    2655, 
    3741, 
    5683, 
    3440, 
    5890, 
    2226, 
    5859, 
    3843, 
    3840, 
    3130, 
    3811, 
    3441, 
    6054, 
    2221, 
    5891, 
    3153, 
    3924, 
    3377, 
    2522, 
    2719, 
    6041, 
    5111, 
    3385, 
    5948, 
    8240, 
    3551, 
    3831, 
    5927, 
    3289, 
    10078, 
    3382, 
    3519, 
    3356, 
    6093, 
    6194
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00746

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "418.51"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 463,
            "rows_produced_per_join": 463,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6151,5696,2698,5721,5621,5724,3605,5944,4951,5830,2340,5887,3354,3155,3834,2737,3308,5892,3306,5848,3397,2352,2431,5934,3841,5114,2339,3212,3389,2924,1626,3350,4163,3392,6098,5811,3390,4934,2862,5719,4960,5706,5720,4933,5850,5821,2922,5849,5828,5703,5832,5824,5798,3603,2693,3928,2338,5826,5801,5864,5829,3301,5852,4894,3660,5928,5822,5847,5854,5896,2341,5794,2702,3147,6099,3828,5898,5788,5932,3649,3520,3529,4962,1668,3146,4958,4942,3809,8586,3518,3148,3918,8372,3215,3213,2222,3400,5691,5687,3733,3552,2805,3232,4915,6025,3149,3416,3157,3589,5791,3845,3150,2481,3822,4976,3115,3740,3123,2228,3743,3112,3944,3664,3126,2230,2655,3741,5683,3440,5890,2226,5859,3843,3840,3130,3811,3441,6054,2221,5891,3153,3924,3377,2522,2719,6041,5111,3385,5948,8240,3551,3831,5927,3289,10078,3382,3519,3356,6093,6194))",
            "cost_info": {
              "read_cost": "202.06",
              "eval_cost": "46.30",
              "prefix_cost": "248.36",
              "data_read_per_join": "7K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 23,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "115.75",
              "eval_cost": "2.32",
              "prefix_cost": "410.41",
              "data_read_per_join": "72K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "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",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 23,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "5.79",
              "eval_cost": "2.32",
              "prefix_cost": "418.51",
              "data_read_per_join": "370"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1626 166,492M
1668 452,424,423,166,492M 0
2221 424,423,451,166M 0
2222 424,423,451,166M 0
2226 424,423,450,166M 0
2228 166,424,450,423M 0
2230 424,423,450,166M 0
2338 424,423,452,166M 0
2339 424,423,452,166M 0
2340 424,423,450,166M 0
2341 424,423,450,166M 0
2352 424,423,450,166M 0
2431 423,424,450,166M 0
2481 424,423,451,166M 0
2522 423,424,452,166M 0
2655 423,424,450,166M 0
2693 423,424,166M 0
2698 450,424,423,166M 0
2702 423,424,450,166M 0
2719 423,424,450,166M 0
2737 423,424,451,166M 0
2805 424,423,492,166M 0
2862 423,425,166M 0
2922 423,424,450,166M 0
2924 423,424,451,166M 0
3112 423,424,452,166M 0
3115 423,424,452,492,166M 0
3123 451,424,423,166M 0
3126 423,424,451,166M 0
3130 477,423,166M 0
3146 423,424,450,166M 0
3147 423,424,450,166M 0
3148 423,424,450,166M 0
3149 423,424,450,166M 0
3150 423,424,450,166M 0
3153 423,451,424,166M 0
3155 423,424,451,166M 0
3157 423,424,450,166M 0
3212 448,423,166M 0
3213 450,423,424,166M 0
3215 450,424,423,166M 0
3232 423,448,166M 0
3289 450,424,423,166M 0
3301 423,424,450,166M 0
3306 450,424,423,166M 0
3308 423,448,166M 0
3350 424,423,166M 0
3354 423,448,166M 0
3356 424,423,166M 0
3377 492,424,423,166M 0
3382 423,424,450,166M 0
3385 423,424,450,166M 0
3389 423,424,166M 0
3390 423,424,166M 0
3392 423,424,166M 0
3397 448,423,166M 0
3400 448,423,166M 0
3416 424,423,166M 0
3440 166,423,448M 0
3441 166,423,448M 0
3518 423,448,166M 0
3519 423,424,166M 0
3520 423,424,450,166M 0
3529 423,424,450,166M 0
3551 424,423,166M 0
3552 423,424,450,166M 0
3589 423,449,166M 0
3603 451,424,423,166M 0
3605 424,423,166,451M 0
3649 423,492,166M 0
3660 166,423,448M 0
3664 423,424,450,166M 0
3733 423,166,449M 0
3740 166,423,448M 0
3741 423,166,448M 0
3743 423,166,448M 0
3809 423,424,450,166M 0
3811 423,449,166M 0
3822 452,424,423,166M 0
3828 423,448,166M 0
3831 423,424,450,166M 0
3834 423,424,450,166M 0
3840 423,424,450,166M 0
3841 448,166M
3843 423,424,450,166M 0
3845 423,424,450,166M 0
3918 448,423,166M 0
3924 423,426,166M 0
3928 423,448,166M 0
3944 425,423,166M 0
4163 423,166M 0
4894 166,423,449M 0
4915 166,423,449M 0
4933 423,520,166M 0
4934 423,520,166M 0
4942 423,520,166M 0
4951 423,520,166M 0
4958 423,166,520M 0
4960 423,520,166M 0
4962 166,423,449M 0
4976 166,423,449M 0
5111 450,423,424,166M 0
5114 450,423,424,166M 0
5621 423,449,166M 0
5683 423,585,166M 0
5687 423,449,166M 0
5691 423,449,166M 0
5696 423,449,166M 0
5703 423,449,166M 0
5706 423,449,166M 0
5719 423,449,166M 0
5720 423,449,166M 0
5721 423,585,166M 0
5724 423,585,166M 0
5788 423,451,424,166M 0
5791 450,424,423,166M 0
5794 450,424,423,166M 0
5798 423,450,424,166M 0
5801 423,424,450,166M 0
5811 423,424,451,166M 0
5821 423,477,166M 0
5822 426,424,423,166M 0
5824 423,477,166M 0
5826 426,424,423,166M 0
5828 423,477,166M 0
5829 423,424,450,166M 0
5830 426,424,423,166M 0
5832 423,477,166M 0
5847 423,424,450,166M 0
5848 423,424,450,166M 0
5849 426,424,423,166M 0
5850 423,477,166M 0
5852 423,424,450,166M 0
5854 426,424,423,166M 0
5859 423,424,426,166M 0
5864 426,424,423,166M 0
5887 423,424,451,166M 0
5890 423,424,450,166M 0
5891 423,424,450,166M 0
5892 423,449,166M 0
5896 423,586,166M 0
5898 423,586,166M 0
5927 308,250,350,423,166,387,383M 0
5928 423,424,450,166M 0
5932 423,308,387,250,350,166,383M 0
5934 250,308,350,423,166,386,382M 0
5944 423,585,166M 0
5948 423,166,585M 0
6025 423,166,585M 0
6041 423,166,585M 0
6054 423,166,585M 0
6093 423,166,449M 0
6098 166,423,586M 0
6099 166,423,586M 0
6151 423,585,166M 0
6194 423,166,449M 0
8240 492,657M
8372 423,657M 0
8586 423,657M 0
10078 448M