-5
SELECT produto, LEAST(preco1, preco2, preco3) FROM precos WHERE codigo=?
The operator least()
, will select the smallest argument of a given query.
With two or more arguments, returns the smallest argument (minimum value)... If the arguments comprise a mixture of numbers and strings, they are compared as numbers.
To update the melhorpreco
, just run the following query:
UPDATE precos SET melhorpreco = LEAST(preco1, preco2, preco3) WHERE codigo=?
Notes
Where were placed the ?
you must enter the registration code you want to make the change.
You can see this SQL Fiddle that demonstrates what you want too.
Give an example of the data contained in the tables and the result you expect with this data
– Sorack
MIN() wouldn’t solve? See this related question too: Show lowest value in Mysql
– UzumakiArtanis
SELECT min(price) FROM table
– Bruno H.