diff --git a/src/metabase/lib/js.cljs b/src/metabase/lib/js.cljs
index f3b733358e01b79f5fca22cfcf868b47c143db27..5448251fbef647bd63cb48d0e7a793bc799f3f78 100644
--- a/src/metabase/lib/js.cljs
+++ b/src/metabase/lib/js.cljs
@@ -659,9 +659,15 @@
 (defn- returned-columns*
   "Inner implementation for [[returned-columns]], which wraps this with caching."
   [a-query stage-number]
-  (let [stage (lib.util/query-stage a-query stage-number)]
+  (let [stage          (lib.util/query-stage a-query stage-number)
+        unique-name-fn (lib.util/unique-name-generator)]
     (->> (lib.metadata.calculation/returned-columns a-query stage-number stage)
-         (map #(assoc % :selected? true))
+         (map #(-> %
+                   (assoc :selected? true)
+                   ;; Unique names are required by the FE for compatibility.
+                   ;; This applies only for JS; Clojure usage should prefer `:lib/desired-column-alias` to `:name`, and
+                   ;; that's already unique by construction.
+                   (update :name unique-name-fn)))
          to-array)))
 
 (defn ^:export returned-columns
diff --git a/test/metabase/lib/js_test.cljs b/test/metabase/lib/js_test.cljs
index e0f2c34abe91404da265686786556b2990112793..e2322ea770f59ef11a8d87afd61115f1947e6bf3 100644
--- a/test/metabase/lib/js_test.cljs
+++ b/test/metabase/lib/js_test.cljs
@@ -398,3 +398,16 @@
            :day]
           (lib.js/expression-clause "time-interval" [(meta/field-metadata :products :created-at)
                                                      (lib.js/expression-clause "interval" [10 "day"] nil) "day"] nil)))))
+(deftest ^:parallel returned-columns-unique-names-test
+  (testing "returned-columns should ensure the :name fields are unique (#37517)"
+    (let [query (-> (lib/query meta/metadata-provider (meta/table-metadata :orders))
+                    (lib/join (lib/join-clause (meta/table-metadata :orders)
+                                               [(lib/= (meta/field-metadata :orders :id)
+                                                       (lib/with-join-alias (meta/field-metadata :orders :id)
+                                                         "Orders"))])))]
+      (is (= #{1}
+             (->> (lib.js/returned-columns query -1)
+                  (map :name)
+                  frequencies
+                  vals
+                  set))))))