Applying mathematics directly to database table

When your company decides to reduce the prices of all products to 5% during this difficult economic time, what will you do to adjust the product prices in your database. Here is what I will show you.

If you perform the query directly to production database, first, I would recommend you duplicate the product table in case you enter an incorrect query. I always do this when I run query to change data in database.

Then write you query

UPDATE tbl_products SET price = price – (price * 0.05) ;

If your company just want to reduce the prices of products in a certain category, you can filter by category id.

UPDATE tbl_products SET price = price – (price * 0.05)  where cat_id = 5;