How to Increase or Decrease the price of all products in the table using SQL.

Here, the main focus is to update the field (here PRICE field ) value by adding some number or subtracting a number or adding a percentage amount directly in the TABLE using SQL command.

Note: When You are Going to Execute this command, I prefer you to keep a backup of your data. Sometimes after Executing a wrong command by mistake, as a effect may be your whole data be lost or that particular FIELD’s data be lost.

Here, TABLE NAME = ‘product’ and TABLE FIELD = ‘price’

# Update the price by 10% of the price for product=1

UPDATE `product` SET `price` = ROUND(`price` * (0.1), 0) WHERE `id` =1
# Update the price by Adding 10% of the price for product=1.
# New price will be, Price = price + (price * 10%)

UPDATE `product` SET `price` = `price` + ROUND(`price` * (0.1), 0) WHERE `product_id` =1
# Update the price by decreasing the existing price by 10% for product id=1.

UPDATE `product` SET `price` = (`price` - ROUND(`price` * (0.1), 0)) WHERE `product_id` =1

If you have any Query regarding this or have any Suggestion, please comment below.

Leave a Comment