   (member1o field (:query-fields query)))
 
 (defn- fields< [query f1 f2]
-  (fresh [group-1 group-2, group-position-1 group-position-2]
-    (featurec f1 {:group group-1, :group-position group-position-1})
-    (featurec f2 {:group group-2, :group-position group-position-2})
+  (fresh [g1 g2, gp1 gp2]
+    (featurec f1 {:group g1, :group-position gp1})
+    (featurec f2 {:group g2, :group-position gp2})
     (conda
-     ((ar/< group-1 group-2))
-     ((== group-1 group-2) (ar/< group-position-1 group-position-2)))))
+     ((ar/< g1 g2))
+     ((== g1 g2) (conda
+                  ((!= g1 (field-groups :other)) (ar/< gp1 gp2))
+                  ((== g1 (field-groups :other)) (fresh [p1 p2, t1 t2]
+                                                   (featurec f1 {:position p1, :special-type-group t1})
+                                                   (featurec f2 {:position p2, :special-type-group t2})
+                                                   (conda
+                                                    ((ar/< p1 p2))
+                                                    ((== p1 p2) (conda
+                                                                 ((ar/< t1 t2))
+                                                                 ((== t1 t2) (ar/< gp1 gp2))))))))))))
 
 (defn- resolve+order-cols [query]
   {:post [(sequential? %) (every? map? %)]}

       :columns (mapv name columns)
       :rows    (for [row results]
                  (mapv row columns))})))

;; (require 'metabase.driver)
;; (require 'metabase.test.data)
;; (require 'metabase.test.data.datasets)
;; (defn x []
;;   (metabase.test.data.datasets/with-dataset
;;     :postgres
;;     (metabase.driver/process-query
;;      {:type :query,
;;       :database (metabase.test.data/db-id),
;;       :query
;;       {:source_table (metabase.test.data/id :venues),
;;        :filter
;;        ["INSIDE"
;;         (metabase.test.data/id :venues :latitude)
;;         (metabase.test.data/id :venues :longitude)
;;         10.0649
;;         -165.379
;;         10.0641
;;         -165.371],
;;        :aggregation ["rows"],
;;        :breakout [nil],
;;        :limit nil}})))

                                :field-name   :name
                                :special-type :special_type
                                :table-id     :table_id})
             (dissoc :position :group :group-position :special-type-group))))

(defn- add-fields-extra-info
  "Add `:extra_info` about `ForeignKeys` to `Fields` whose `special_type` is `:fk`."
