- 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
Update with multiple values in MySQL WHERE clause
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20), -> Age int, -> CountryName varchar(10) -> ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,'Chris',34,'AUS'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(101,'Chris',31,'US'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(102,'David',25,'UK'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(103,'Carol',28,'AUS'); Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+------+-------+------+-------------+ | Id | Name | Age | CountryName | +------+-------+------+-------------+ | 100 | Chris | 34 | AUS | | 101 | Chris | 31 | US | | 102 | David | 25 | UK | | 103 | Carol | 28 | AUS | +------+-------+------+-------------+ 4 rows in set (0.00 sec)
Here is the query to update with multiple values in WHERE clause −
mysql> update DemoTable -> set Name='Robert' -> where Age=31 and CountryName='US'; Query OK, 1 row affected (0.44 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable;
This will produce the following output −
+------+--------+------+-------------+ | Id | Name | Age | CountryName | +------+--------+------+-------------+ | 100 | Chris | 34 | AUS | | 101 | Robert | 31 | US | | 102 | David | 25 | UK | | 103 | Carol | 28 | AUS | +------+--------+------+-------------+ 4 rows in set (0.00 sec)
- Related Articles
- Can we fetch multiple values with MySQL WHERE Clause?
- How to update multiple rows using single WHERE clause in MySQL?
- Update multiple values in a table with MySQL IF Statement
- Multiple Where clause in C# Linq
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- How can we update columns values on multiple rows with a single MySQL UPDATE statement?
- Multiple WHERE with LIMIT in MySQL?
- How to use MySQL VIEW with WHERE clause?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- What MySQL returns if sub-query, used to assign new values in the SET clause of UPDATE statement, returns multiple rows?
- What MySQL returns when we use DISTINCT clause with the column having multiple NULL values?
- MySQL select query with multiple WHERE?
- Update values in multiple documents with multi parameter in MongoDB?
- How to use MySQL Date functions with WHERE clause?
- How to update multiple rows and left pad values in MySQL?

Advertisements