samedi 14 février 2015

Sqlite Update columns

I have 5 columns in my table : id, x, y, source, distance.


For every id, i want to find the nearest x & y values and update that value in the distance field along with its id in source.


I'm able to update the distance with the below query:



UPDATE item SET distance = ( SELECT MIN( ABS (a.x - item.x) + ABS (a.y - item.y) )
FROM item AS a WHERE a.id != item.id )


However i'm unable to update the source because sqlite does not support multiple column update from a single select.


When i try to put the query in the where condition, i get the error, no such column as item.x



UPDATE item SET link = ( SELECT id FROM item AS a WHERE a.id != item.id
ORDER BY ABS (a.x - item.x) + ABS (a.y - item.y) LIMIT 1 )


How do i resolve my query ?


Aucun commentaire:

Enregistrer un commentaire