Examples of MySQL requests for modification / update. In MySQL, an UPDATE statement is used to update / modify existing records.

Query U001. The following query MySQL updates the values of the price field, increasing by 10% the prices for products with code 3 in the m_income table:

UPDATE m_income 
SET price = price*1.1
WHERE product_id=3;

Query U002. The following MySQL update request increases the number of all products in the m_income table by 22 units, the names of which begin with the word "Oil" ("Масло"):

UPDATE m_income 
SET amount = amount+22
WHERE product_id IN (SELECT id FROM m_product WHERE title LIKE "Масло%");

Query U003. The following MySQL query in the m_outcome table reduces by 2% the prices for all products produced by LLC "Sladkoe" ("Сладкое"):

UPDATE m_outcome SET price = price*0.98
WHERE product_id IN
(SELECT a.id FROM m_product a INNER JOIN m_supplier b
ON a.supplier_id=b.id WHERE b.title='ООО "Сладкое"');

Query U004. The following MySQL query for a change in the m_income table increases:

- by 10% of the price of goods of category 1;
- by 20% of the price of goods of category 2;
- by 17% of the price of goods of category 3.
Prices for goods of other categories remain unchanged:

UPDATE m_income a 
INNER JOIN m_product b ON a.product_id = b.id
INNER JOIN m_category c ON b.ctgry_id = c.id
SET price = CASE c.id
WHEN 1 THEN price * 1.1
WHEN 2 THEN price * 1.2
WHEN 3 THEN price * 1.17
ELSE price END;