
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Perform MySQL update with AND operator
Let us first create a table −
mysql> create table DemoTable613 (Id int,Age int,isMarried tinyint(1)); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable613 values(100,29,0); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable613 values(200,22,0); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable613 values(300,30,1); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable613;
This will produce the following output −
+------+------+-----------+ | Id | Age | isMarried | +------+------+-----------+ | 100 | 29 | 0 | | 200 | 22 | 0 | | 300 | 30 | 1 | +------+------+-----------+ 3 rows in set (0.00 sec)
Following is the query to perform MySQL update with AND operator −
mysql> update DemoTable613 set isMarried=(Age=29 AND (Id=100)); Query OK, 2 rows affected (0.24 sec) Rows matched: 3 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable613;
This will produce the following output −
+------+------+-----------+ | Id | Age | isMarried | +------+------+-----------+ | 100 | 29 | 1 | | 200 | 22 | 0 | | 300 | 30 | 0 | +------+------+-----------+ 3 rows in set (0.00 sec)
- Related Articles
- UPDATE with logical AND operator in MySQL
- How to perform Increment in MySQL Update?
- Can we perform MySQL UPDATE and change nothing in a table?
- Update a specific MongoDB document in array with $set and positional $ operator?
- Update a MySQL table with Java MySQL
- Perform MySQL UPDATE on the basis of DATE value in another column
- Perform multiple updates with bulk operations and update elements in an array in MongoDB
- MySQL: update field with Group By?
- Does MySQL update with regexp possible?
- MySQL XOR operator with IN clause?
- Can we update MySQL with if condition?
- Update table with duplicate ids in MySQL
- Update a MySQL column with JSON format?
- Using Update statement with TINYINT in MySQL?
- Perform multiple inserts with INSERT INTO SELECT and UNION in MySQL

Advertisements