- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to increase item value price for multiple items in a single query?
To increase item value for multiple items in a single query, you can use the CASE statement in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> ProductName varchar(20), -> ProductPrice int -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Product-1',700); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Product-2',1000); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Product-3',3000); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+--------------+ | ProductName | ProductPrice | +-------------+--------------+ | Product-1 | 700 | | Product-2 | 1000 | | Product-3 | 3000 | +-------------+--------------+ 3 rows in set (0.00 sec)
Here is the MySQL query to increase item value price for multiple items −
mysql> update DemoTable -> set ProductPrice= -> case when ProductName='Product-1' then ProductPrice+((ProductPrice*20)/100) -> when ProductName='Product-2' then ProductPrice+((ProductPrice*40)/100) -> when ProductName='Product-3' then ProductPrice+((ProductPrice*60)/100) -> end; Query OK, 3 rows affected (0.14 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+--------------+ | ProductName | ProductPrice | +-------------+--------------+ | Product-1 | 840 | | Product-2 | 1400 | | Product-3 | 4800 | +-------------+--------------+ 3 rows in set (0.00 sec)
- Related Articles
- Multiple COUNT() for multiple conditions in a single MySQL query?
- How to write a single MySQL query for displaying a value for multiple inputs?
- MySQL query to sort multiple columns together in a single query
- MySQL query to return all items in a single row
- Implement multiple COUNT() in a single MySQL query
- Change multiple columns in a single MySQL query?
- Insert multiple rows in a single MySQL query
- MySQL update multiple records in a single query?
- Counting different distinct items in a single MySQL query?
- How to get multiple rows in a single MySQL query?
- How to obtain multiple rows in a single MySQL query?
- Get multiple count in a single MySQL query for specific column values
- Implement multiple LIKE operators in a single MySQL query
- MySQL query to get the highest value from a single row with multiple columns
- Use LIKE % to fetch multiple values in a single MySQL query

Advertisements