mercredi 14 octobre 2015

How to run an SQL UPDATE query where a field is modified and then used

Is the following posible on SQL? (Using SQLITE3)

UPDATE Table SET
Value1 = (SELECT ...)
Value2 = Value3/Value1; # The new value1!!! Not the value currently on the DB

Right now I need to do something like:

UPDATE Table SET
Value1 = (SELECT ...)
Value2 = Value3/(SELECT ...);

This makes the code quite long. Imagine it is not only Value1 I am updating but other fields too.

So the only solution I found is to do 2 UPDATES. First:

UPDATE Table SET
Value1 = (SELECT ...);

And then

UPDATE Table SET
Value2 = Value3/Value1;

Anyone with a more "beautiful" way of doing this?

Thanks,

Aucun commentaire:

Enregistrer un commentaire