SELECT 
  pf.feature_id, 
  pf.feature_style, 
  pf.position, 
  pf.purpose, 
  pf.display_on_catalog, 
  pfd.description, 
  pfd.internal_name, 
  pfd.prefix, 
  pfd.suffix, 
  (
    CASE WHEN pf.purpose = 'group_catalog_item' THEN 0 ELSE 1 END
  ) AS purpose_position 
FROM 
  cscart_product_features AS pf 
  INNER JOIN cscart_product_features_descriptions AS pfd ON pf.feature_id = pfd.feature_id 
  AND pfd.lang_code = 'vi' 
WHERE 
  pf.feature_id IN (
    24836, 23521, 23432, 23233, 20077, 21323, 
    23236, 23234, 21324, 21893, 20083, 
    21322, 23235, 24974, 21594, 19747, 
    19746
  ) 
ORDER BY 
  purpose_position ASC, 
  pf.position ASC, 
  pf.feature_id ASC

Query time 0.00430

JSON explain

{
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "read_sorted_file": {
          "filesort": {
            "sort_key": "case when pf.purpose = 'group_catalog_item' then 0 else 1 end, pf.position, pf.feature_id",
            "table": {
              "table_name": "pf",
              "access_type": "range",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["feature_id"],
              "rows": 17,
              "filtered": 100,
              "index_condition": "pf.feature_id in (24836,23521,23432,23233,20077,21323,23236,23234,21324,21893,20083,21322,23235,24974,21594,19747,19746)"
            }
          }
        }
      },
      {
        "table": {
          "table_name": "pfd",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "9",
          "used_key_parts": ["feature_id", "lang_code"],
          "ref": ["dev_db.pf.feature_id", "const"],
          "rows": 1,
          "filtered": 100,
          "index_condition": "pfd.lang_code = 'vi'"
        }
      }
    ]
  }
}

Result

feature_id feature_style position purpose display_on_catalog description internal_name prefix suffix purpose_position
19746 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
19747 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
20077 dropdown_labels 0 group_variation_catalog_item N Chọn vị trà cho Hũ 1 10041_92 - loại trà là nhiên 1
20083 dropdown_labels 0 group_variation_catalog_item N Chọn 1 vị trà mix Chọn 1 vị trà mix 1
21322 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21323 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21324 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21594 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
21893 dropdown_labels 0 group_variation_catalog_item N Lựa chọn Lựa chọn 1
23233 dropdown_labels 0 group_variation_catalog_item N Chọn khối lượng 10600_08 - khối lượng 1
23234 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10600_11 - 60g/100g 1
23235 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10600_12 - 45g/100g 1
23236 dropdown_labels 0 group_variation_catalog_item N Lựa chọn 10601_01 - gram 1
23432 dropdown_labels 0 group_variation_catalog_item N Chọn thiết kế hộp 10262_34 - thiết kế 1
23521 dropdown_labels 0 group_variation_catalog_item N Chọn màu hộp 10046_01 - màu 1
24836 dropdown_labels 0 group_variation_catalog_item N Chọn thiết kế hộp 10262_35 - option 1
24974 dropdown_labels 0 group_variation_catalog_item N Chọn màu 10300_12 1