vendredi 20 mars 2015

Sqlite update with min if smaller than existing

Must misunderstand something basic here, have a couple tables:



table1 (id, minValue)
table2 (table1Id, value)


If I run the query:



UPDATE table1 SET minValue = (SELECT MIN(value) FROM table2 WHERE table1.id == table2.table1Id);


I get the expected values. However if I run this query the minValues remain null:



UPDATE table1 SET minValue = MIN(minValue, (SELECT MIN(value) FROM table2 WHERE table1.id == table2.table1Id));


I will be updating the minValue from multiple tables so I want to make sure it stays smaller than the incoming values but still gets updated when minValue is still null.


Aucun commentaire:

Enregistrer un commentaire