invalid reference to FROM-clause entry for table "d"
<p>As part of the k-means algorithm, I am trying to update the cluster each item belongs to as in the below query. Problem is, I cannot seem to be able to reference table d inside the nested query.</p>

<pre><code>UPDATE algorithms.km_crimes d SET cluster_id = c.id 
FROM (SELECT id FROM algorithms.km_cluster_centres c 
ORDER BY |/ (POW(d.latitude-c.latitude,2)+POW(d.longitude-c.longitude,2))      
ASC LIMIT 1) AS c
WHERE d.cluster_id IS DISTINCT FROM c.id;
</code></pre>

<p>Can anyone suggest how to restructure the query? I've tried too many modifications to count</p>