                       :queryable? true
                       :field :environments.environment}}
 
-      :selection {:from [:factsets]
+      :selection {:from [[:factsets :fs]]
                   :left-join [:environments
-                              [:= :factsets.environment_id :environments.id]
+                              [:= :fs.environment_id :environments.id]
                               :producers
-                              [:= :producers.id :factsets.producer_id]]}
+                              [:= :producers.id :fs.producer_id]]}
 
       :relationships (merge certname-relations
                             {"environments" {:local-columns ["environment"]

                                        :column cinfo
                                        :value (su/munge-jsonb-for-storage value)})

                :queryable-json
                (map->JsonbPathBinaryExpression {:field column-name
                                                 :column-data cinfo
                                                 :value (su/munge-jsonb-for-storage value)

                    :field :timestamp}
       "facts" {:type :queryable-json
                :queryable? true
                :field {:select [(h/row-to-json :facts_data)]
                        :from [[{:select [[(hcore/raw "json_agg(json_build_object('name', t.name, 'value', t.value))")
                                           :data]
                                          [(hsql-hash-as-href "fs.certname" :factsets :facts)
                                           :href]]
                                 :from [[{:select [[:key :name] :value :certname]
                                          :from [(hcore/raw "jsonb_each(fs.volatile || fs.stable)")]}
                                         :t]]}
                                :facts_data]]}}
       "certname" {:type :string
                   :queryable? true
                   :field :fs.certname}
       "hash" {:type :string
               :queryable? true
               :field (hsql-hash-as-str :fs.hash)}
       "producer_timestamp" {:type :timestamp
                             :queryable? true
                             :field :fs.producer_timestamp}
       "producer" {:type :string
                   :queryable? true
                   :field :producers.name}
