SELECT 
  category_id, 
  parent_id 
FROM 
  cscart_categories 
WHERE 
  parent_id IN(
    5037, 
    5001, 
    5064, 
    5041, 
    5010, 
    5011, 
    5055, 
    5002, 
    5048, 
    5065, 
    5003, 
    5047, 
    5066, 
    5004, 
    5054, 
    5067, 
    5005, 
    5006, 
    5007, 
    5096, 
    5112, 
    5113, 
    5008, 
    5095, 
    5009, 
    4917, 
    4918, 
    5038, 
    5070, 
    4900, 
    4903, 
    5109, 
    4910, 
    4911, 
    4909, 
    5026, 
    4945, 
    5100, 
    4985, 
    4974, 
    4939, 
    4949, 
    4950, 
    4951, 
    4954, 
    4952, 
    4953, 
    4955, 
    4956, 
    4944, 
    4946, 
    5106, 
    5032, 
    5018, 
    5039, 
    5078, 
    4914, 
    4915, 
    4997, 
    5062, 
    4996, 
    3417, 
    5063, 
    5061, 
    5141, 
    5140, 
    5132, 
    5136, 
    5068, 
    5045, 
    5046, 
    5156, 
    4981, 
    4976, 
    5030, 
    5028, 
    5029, 
    5072, 
    4991, 
    4913, 
    5099, 
    5111, 
    5155, 
    5173, 
    5175, 
    5049, 
    5023, 
    4921, 
    4941, 
    4942, 
    5105, 
    5120, 
    4988, 
    4977, 
    4975, 
    5056, 
    5182, 
    5185, 
    5080, 
    4931, 
    5021, 
    5073, 
    5087, 
    4986, 
    4935, 
    4982, 
    5031, 
    5052, 
    4990, 
    5024, 
    4992, 
    5022, 
    5183, 
    4989, 
    5076, 
    5075, 
    5158, 
    4940, 
    4979, 
    5051, 
    4912, 
    5033, 
    5035, 
    4906, 
    4907, 
    5176, 
    5089, 
    4980, 
    4901, 
    4899, 
    4902, 
    5012, 
    5184, 
    5159, 
    5088, 
    5147, 
    4987, 
    3438, 
    4937, 
    5129, 
    5126, 
    5127, 
    5017, 
    499, 
    4925, 
    4924, 
    5174, 
    5114, 
    5097, 
    5098, 
    5115, 
    5119, 
    5104, 
    4998, 
    5020, 
    4999, 
    5000, 
    5019, 
    5057, 
    5040, 
    5094, 
    5110, 
    4928, 
    5122, 
    5121, 
    5144, 
    5143, 
    5142, 
    5124, 
    5123, 
    5015, 
    5166, 
    5138, 
    5128, 
    5139, 
    5125, 
    3446, 
    4920, 
    5060, 
    5059, 
    5025, 
    5016, 
    5034, 
    5013, 
    5133, 
    5134, 
    5137, 
    5135, 
    5145, 
    5131, 
    5146, 
    4933, 
    4934, 
    4929, 
    4930, 
    5069, 
    5168, 
    4908, 
    5082, 
    5081, 
    5083, 
    5077, 
    5157, 
    5053, 
    4993, 
    4994, 
    4932, 
    5074, 
    5058, 
    4984, 
    5091, 
    5085, 
    5050, 
    5027, 
    5090, 
    5107, 
    5092, 
    5167, 
    5086, 
    4927, 
    4923, 
    4904, 
    4978, 
    5084, 
    4919, 
    4943, 
    4959, 
    4964, 
    4962, 
    4967, 
    4970, 
    4973, 
    4957, 
    4963, 
    4960, 
    4965, 
    4968, 
    4971, 
    4958, 
    4961, 
    4966, 
    4969, 
    4972, 
    5130, 
    5152, 
    5161, 
    5187, 
    5093, 
    5108, 
    5071, 
    4983, 
    4938, 
    4995, 
    5036, 
    5102, 
    5117, 
    5103, 
    5118, 
    5101, 
    5116, 
    5149, 
    5148, 
    5150, 
    5151, 
    5042, 
    5044, 
    5043, 
    4947, 
    4948, 
    5186, 
    5172, 
    5160, 
    5181, 
    5162, 
    5178, 
    5169, 
    5171, 
    5163, 
    5179, 
    5180, 
    5154, 
    5164, 
    5177, 
    5165, 
    5153, 
    5170, 
    3252, 
    3255, 
    911, 
    4926, 
    5079, 
    4922, 
    5014, 
    860, 
    1967, 
    849, 
    835, 
    4905, 
    1552, 
    2372, 
    2346, 
    897, 
    3542, 
    2486, 
    929, 
    3481, 
    2028, 
    3471, 
    921, 
    3476, 
    884, 
    1966, 
    1982, 
    2698, 
    2688, 
    2708, 
    3212, 
    3316, 
    3477, 
    2955, 
    890, 
    3170, 
    952, 
    3415, 
    1971, 
    2374, 
    2349, 
    2984, 
    418, 
    668, 
    2947, 
    1306, 
    1519, 
    478, 
    644, 
    568, 
    421, 
    1527, 
    2706, 
    758, 
    1069, 
    1192, 
    1300, 
    2009, 
    1530, 
    1521, 
    1974, 
    2714, 
    2194, 
    3492, 
    3485, 
    3487, 
    3269, 
    3315, 
    3271, 
    3273, 
    896, 
    3493, 
    3497, 
    3501, 
    3505, 
    3509, 
    3513, 
    3517, 
    3521, 
    3543, 
    4000, 
    3547, 
    3550, 
    5188, 
    5197, 
    5198, 
    5202, 
    3452, 
    5204, 
    5205, 
    5206
  ) 
  AND category_id != 414

Query time 0.00751

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "368.89"
    },
    "table": {
      "table_name": "cscart_categories",
      "access_type": "ALL",
      "possible_keys": [
        "PRIMARY",
        "parent",
        "p_category_id"
      ],
      "rows_examined_per_scan": 3444,
      "rows_produced_per_join": 3016,
      "filtered": "87.57",
      "cost_info": {
        "read_cost": "67.29",
        "eval_cost": "301.60",
        "prefix_cost": "368.89",
        "data_read_per_join": "10M"
      },
      "used_columns": [
        "category_id",
        "parent_id"
      ],
      "attached_condition": "((`s2cart`.`cscart_categories`.`parent_id` in (5037,5001,5064,5041,5010,5011,5055,5002,5048,5065,5003,5047,5066,5004,5054,5067,5005,5006,5007,5096,5112,5113,5008,5095,5009,4917,4918,5038,5070,4900,4903,5109,4910,4911,4909,5026,4945,5100,4985,4974,4939,4949,4950,4951,4954,4952,4953,4955,4956,4944,4946,5106,5032,5018,5039,5078,4914,4915,4997,5062,4996,3417,5063,5061,5141,5140,5132,5136,5068,5045,5046,5156,4981,4976,5030,5028,5029,5072,4991,4913,5099,5111,5155,5173,5175,5049,5023,4921,4941,4942,5105,5120,4988,4977,4975,5056,5182,5185,5080,4931,5021,5073,5087,4986,4935,4982,5031,5052,4990,5024,4992,5022,5183,4989,5076,5075,5158,4940,4979,5051,4912,5033,5035,4906,4907,5176,5089,4980,4901,4899,4902,5012,5184,5159,5088,5147,4987,3438,4937,5129,5126,5127,5017,499,4925,4924,5174,5114,5097,5098,5115,5119,5104,4998,5020,4999,5000,5019,5057,5040,5094,5110,4928,5122,5121,5144,5143,5142,5124,5123,5015,5166,5138,5128,5139,5125,3446,4920,5060,5059,5025,5016,5034,5013,5133,5134,5137,5135,5145,5131,5146,4933,4934,4929,4930,5069,5168,4908,5082,5081,5083,5077,5157,5053,4993,4994,4932,5074,5058,4984,5091,5085,5050,5027,5090,5107,5092,5167,5086,4927,4923,4904,4978,5084,4919,4943,4959,4964,4962,4967,4970,4973,4957,4963,4960,4965,4968,4971,4958,4961,4966,4969,4972,5130,5152,5161,5187,5093,5108,5071,4983,4938,4995,5036,5102,5117,5103,5118,5101,5116,5149,5148,5150,5151,5042,5044,5043,4947,4948,5186,5172,5160,5181,5162,5178,5169,5171,5163,5179,5180,5154,5164,5177,5165,5153,5170,3252,3255,911,4926,5079,4922,5014,860,1967,849,835,4905,1552,2372,2346,897,3542,2486,929,3481,2028,3471,921,3476,884,1966,1982,2698,2688,2708,3212,3316,3477,2955,890,3170,952,3415,1971,2374,2349,2984,418,668,2947,1306,1519,478,644,568,421,1527,2706,758,1069,1192,1300,2009,1530,1521,1974,2714,2194,3492,3485,3487,3269,3315,3271,3273,896,3493,3497,3501,3505,3509,3513,3517,3521,3543,4000,3547,3550,5188,5197,5198,5202,3452,5204,5205,5206)) and (`s2cart`.`cscart_categories`.`category_id` <> 414))"
    }
  }
}

Result

category_id parent_id
664 644
669 668
670 668
671 668
672 668
673 668
674 668
675 668
676 668
677 668
678 668
679 668
680 644
685 644
645 644
635 568
636 568
640 568
641 568
628 568
621 568
619 568
620 568
618 568
617 568
616 568
611 568
610 568
605 568
604 568
603 568
585 568
586 568
587 568
579 568
578 568
573 568
572 568
571 568
569 568
567 478
566 478
565 478
564 478
526 478
527 478
469 418
470 418
471 418
472 418
473 418
474 418
475 418
476 418
477 418
479 478
480 478
484 478
493 478
494 478
495 478
496 478
497 478
498 478
500 499
501 499
502 499
503 499
504 499
505 499
506 478
508 478
509 478
510 478
511 478
521 478
522 478
523 478
524 478
525 478
431 421
432 421
433 421
434 421
435 421
436 421
437 421
438 421
439 421
440 421
441 421
442 421
443 421
444 418
445 418
446 418
447 418
448 418
449 418
450 418
451 418
452 418
453 418
454 418
455 418
456 418
457 418
458 418
459 418
460 418
461 418
424 421
423 421
422 421
419 418
420 418
695 644
696 644
697 644
701 644
706 644
713 644
714 644
715 644
716 644
717 644
718 644
719 644
720 644
736 644
737 644
740 644
743 644
749 644
751 644
752 644
759 758
760 758
761 758
762 758
769 758
770 758
771 758
772 758
777 758
781 758
782 758
783 758
784 758
785 758
786 758
787 758
788 758
791 758
792 758
793 758
794 758
795 758
799 758
800 758
801 758
802 758
803 758
804 758
805 758
806 758
807 758
808 758
812 758
815 758
816 758
821 758
822 758
824 849
838 835
841 835
848 849
852 849
853 849
855 849
856 849
857 849
859 849
861 860
882 897
887 3471
888 884
889 897
892 4000
898 897
899 897
900 897
901 897
902 897
903 897
904 897
905 897
906 897
907 897
908 897
909 897
910 897
914 911
920 3477
922 921
926 921
930 929
931 929
932 929
933 929
934 929
935 929
936 929
937 929
938 921
939 921
953 952
954 952
955 952
964 921
982 3476
990 921
999 921
1000 921
1012 921
1018 921
1027 921
1038 921
1056 921
1063 921
1067 921
1070 1069
1081 1069
1082 1069
1089 1069
1090 1069
1093 1069
1094 1069
1095 1069
1096 1069
1097 1069
1098 1069
1101 1069
1114 1069
1115 1069
1117 1069
1118 1069
1130 1069
1131 1069
1132 1069
1133 1069
1140 1069
1141 1069
1142 1069
1143 1974
1193 1192
1197 1192
1198 1192
1278 1192
1279 1192
1283 1192
1301 1300
1304 1300
1305 1300
1307 1306
1308 1300
1309 1192
1310 1192
1311 1192
1312 1192
1313 1192
1314 1192
1325 1192
1326 1192
1327 1192
1328 1192
1329 1306
1331 1306
1332 1306
1333 1306
1334 1192
1335 1306
1336 1306
1337 1306
1338 1306
1339 1306
1340 1306
1344 1306
1345 1306
1346 1306
1347 1306
1348 1306
1351 1306
1352 1306
1353 1306
1354 1306
1364 1306
1365 1306
1366 1306
1367 1306
1383 1306
1384 1306
1386 1306
1388 1192
1402 1306
1403 1192
1415 1192
1416 1192
1417 1192
1441 1192
1446 1192
1447 1192
1448 1192
1449 1192
1450 1192
1454 1192
1455 1192
1459 1192
1478 1306
1479 1192
1492 1192
1493 1192
1498 1192
1499 1306
1500 1300
1501 1192
1520 1519
1522 1521
1528 1527
1529 1519
1531 1530
1532 1519
1533 1530
1534 1527
1535 1530
1536 1519
1537 1530
1538 1530
1541 1530
1542 1530
1543 1530
1544 1530
1545 1530
1546 1519
1548 1530
1549 1519
1551 1530
1565 1530
1566 1530
1567 1530
1569 1530
1570 1519
1575 1519
1576 1530
1577 1530
1578 1521
1587 1521
1596 1519
1597 1527
1604 1527
1605 1530
1606 1527
1607 1527
1608 1527
1609 1527
1610 1527
1611 1519
1613 1530
1614 1530
1615 1530
1618 1519
1619 1530
1620 1527
1621 1519
1622 1519
1623 1519
1625 1527
1627 1530
1628 1530
1633 1521
1637 1521
1647 1521
1655 1521
1673 1530
1675 1530
1677 1521
1775 1521
1808 1521
1839 1530
1840 1530
1841 1530
1842 1530
1843 1530
1845 1530
1846 1519
1847 1519
1848 1519
1857 1530
1870 1552
1871 1530
1876 1527
1877 1527
1880 1519
1881 1519
1882 1527
1883 1519
1884 1519
1885 1530
1891 1530
1894 1530
1895 1530
1896 1527
1897 1530
1898 1530
1902 1530
1903 1530
1919 1527
1920 1527
1921 1974
1922 1530
1923 1519
1924 1530
1925 1530
1926 1519
1927 1530
1928 1530
1929 1530
1933 1530
1934 1521
1935 1530
1936 1530
1937 1527
1938 1530
1939 1530
1940 1530
1941 1530
1945 1527
1946 1530
1947 1519
1948 1530
1949 1519
1950 1519
1951 1519
1952 1527
1953 1519
1954 1530
1955 1519
1956 1530
1957 1530
1958 1521
1962 1530
1963 1530
1964 1519
1965 1519
1968 1967
1969 1967
1970 1967
1972 1971
1975 1974
1981 1971
1984 1974
1993 1974
2007 1974
2008 1971
2010 2009
2011 2009
2012 2009
2013 2009
2014 2009
2020 1974
2029 2028
2045 1974
2047 1971
2049 1974
2064 1966
2065 1974
2070 1971
2071 2028
2073 1971
2076 2028
2086 1982
2092 2028
2109 2028
2125 1974
2126 1974
2140 1974
2155 2028
2156 2028
2167 1974
2168 2028
2179 1974
2189 1974
2195 2194
2196 2194
2197 2194
2198 2194
2199 2194
2200 2194
2201 2194
2202 2194
2203 2194
2204 2194
2205 1974
2219 1974
2226 1974
2233 1974
2246 2028
2262 2028
2275 1971
2291 1974
2295 1974
2301 2028
2316 1974
2321 1971
2345 1971
2347 2346
2350 2349
2351 2349
2354 2349
2366 2349
2373 2372
2375 2374
2376 2372
2377 2346
2378 2346
2379 2374
2380 2346
2381 2372
2382 2374
2384 2346
2385 2372
2386 2374
2415 2372
2416 2346
2417 2346
2419 2372
2420 2372
2421 2372
2422 2372
2423 2374
2427 2374
2428 2346
2437 2374
2438 2374
2443 2372
2444 2374
2448 2372
2449 2372
2450 2372
2451 2346
2457 2374
2460 2372
2461 2374
2464 2372
2465 2349
2466 2372
2467 2374
2483 2372
2484 2374
2485 2346
2487 2486
2488 2486
2496 2372
2498 2372
2499 2486
2501 2486
2502 2374
2505 2349
2506 2349
2507 2349
2535 2349
2548 2349
2550 2349
2558 2349
2559 2349
2583 2349
2584 2349
2585 2486
2588 2372
2599 2374
2613 2349
2614 2346
2617 2346
2622 2346
2623 2346
2624 2374
2625 2346
2626 2346
2627 2372
2628 2372
2629 2372
2630 2372
2631 2486
2632 2346
2633 2346
2634 2372
2637 2374
2638 2372
2643 2372
2645 2349
2646 2349
2649 2349
2650 2374
2651 2346
2652 2349
2653 2349
2654 2374
2671 2346
2672 2374
2673 2346
2674 2374
2675 2372
2676 2374
2678 2349
2679 2372
2682 2486
2684 2486
2687 2372
2699 2698
2707 2706
2709 2708
2715 2714
2719 2698
2724 2706
2725 2688
2728 2706
2733 2706
2734 2688
2735 2688
2739 3477
2753 3477
2754 3477
2755 2706
2766 2698
2768 2706
2775 2706
2778 2708
2779 2688
2780 2706
2789 2706
2796 2698
2800 2688
2801 2706
2851 2706
2852 2706
2853 2706
2871 3477
2922 2708
2934 2708
2937 2706
2944 2955
2945 2708
2948 2947
2949 2947
2950 2947
2951 2947
2952 2947
2953 2947
2954 2947
2956 2955
2957 2955
2958 2955
2959 2708
2974 2708
2981 2708
2985 2984
2987 2698
2992 2984
2993 2984
3004 2708
3005 2984
3006 2984
3007 2984
3008 2706
3012 2708
3016 2706
3026 2714
3028 2706
3037 2708
3038 2706
3043 3315
3044 2706
3048 2708
3055 2706
3092 2706
3095 2706
3111 2698
3134 2984
3135 3477
3141 2714
3147 2714
3149 2688
3151 2984
3152 2698
3171 3170
3172 3170
3173 3170
3174 3170
3175 3170
3176 3170
3177 3170
3178 3170
3179 3170
3180 3170
3181 2708
3182 2706
3190 2708
3191 2708
3199 2688
3200 2708
3213 3212
3214 3212
3215 3212
3216 3212
3217 3212
3218 3212
3219 3212
3220 2708
3236 2708
3237 2708
3242 2708
3243 2708
3244 2708
3245 2688
3247 2714
3250 2708
3256 3481
3259 3269
3260 3315
3264 3315
3266 3485
3268 3487
3274 3269
3275 2984
3276 2984
3277 2984
3278 2984
3279 2984
3280 2984
3281 2984
3288 2984
3289 2706
3290 3477
3291 2706
3317 2706
3333 2698
3342 2698
3343 2984
3344 2706
3350 2706
3364 2688
3366 2708
3368 2698
3374 2984
3388 2984
3397 2984
3407 2984
3413 2708
3414 2706
3416 3415
3418 3417
3419 3417
3420 3415
3421 3415
3422 3415
3423 3452
3424 3415
3425 3415
3426 3415
3427 3415
3428 3415
3429 3415
3430 2708
3431 3415
3432 3415
3433 3415
3434 3415
3435 3415
3436 3415
3437 3415
3439 3415
3440 3415
3441 3415
3442 3415
3443 3415
3444 3415
3445 3415
3447 3446
3448 3446
3449 3446
3450 3446
3451 3415
3453 3415
3454 3415
3455 3415
3456 3415
3457 3415
3458 3415
3459 3415
3460 3415
3461 3415
3462 3415
3463 3415
3464 3415
3465 3415
3466 3415
3467 1967
3468 3415
4916 5188
4936 5188
886 884
1854 1552
2274 1966
2936 3252
3267 3255
854 849
2418 2346
837 835
895 3543
2986 3252
3488 3487
3262 3481
918 911
4001 4000
885 884
942 3476
1852 1552
2063 1966
2117 1982
2282 1966
916 911
851 3550
2439 2346
840 835
864 860
3489 3487
3257 3252
4896 3543
947 3476
1603 1552
2016 1966
2019 1966
2218 1982
913 911
858 3550
846 835
872 860
3490 3487
3544 4000
4897 3543
1624 1552
2137 1982
2341 1966
3254 3252
850 3550
842 835
915 3542
3150 3487
3470 3252
3161 2698
917 911
1030 3476
1009 3476
1556 1552
2115 1966
2175 1966
2260 1982
847 835
873 860
3251 3252
1062 3476
1626 1552
2119 1966
836 835
1006 3476
1553 1552
1849 1552
2273 1982
2277 1966
845 835
879 860
919 3542
956 3476
1612 1552
1850 1552
2256 1982
2323 1966
844 835
881 911
1008 3476
1851 1552
2062 1966
2258 1982
2336 1966
843 835
875 860
912 911
2002 1982
2177 1966
2257 1982
2342 1982
839 835
3482 3255
3486 3485
3478 3481
3523 3521
3522 3521
3518 3517
3514 3513
3510 3509
3506 3505
3502 3501
3498 3497
3494 3493
3548 3547
5189 5188
5199 5198
1853 1552
1983 1982
2005 1982
2118 1982
2178 1966
831 835
2015 1982
825 835
5196 884
1855 1552
2276 1982
2300 1982
5195 4000
1856 1552
1994 1982
2143 1982
2261 1982
2294 1982
1858 1552
2072 1982
2278 1982
3551 1982
1859 1552
2129 1982
2269 1982
2315 1982
1860 1552
1995 1982
2136 1982
2290 1982
1861 1552
1862 1552
2320 1982
3545 860
1863 1552
2343 1982
3479 3481
3483 3255
3524 3521
3519 3517
3515 3513
3511 3509
3507 3505
3503 3501
3499 3497
3495 3493
3549 3547
5190 5188
5200 5198
1864 1552
1865 1552
1866 1552
1867 1552
1868 1552
1869 1552
1872 1552
1873 1552
3484 3255
3537 3521
3520 3517
3516 3513
3512 3509
3508 3505
3504 3501
3500 3497
3496 3493
5191 5188
5201 5198
2878 2698
5192 5188
2802 2698
2923 2698
3115 2698
5193 5188
3023 2688
2690 2688
5194 5188