
- 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 on the basis of DATE value in another column
Let us first create a table −
mysql> create table DemoTable( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100), AdmissionDate date ); Query OK, 0 rows affected (0.42 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Name,AdmissionDate) values('Chris','2019-11-21'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Name,AdmissionDate) values('Mike','2019-03-11'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name,AdmissionDate) values('Sam','2018-04-01'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name,AdmissionDate) values('Carol','2019-05-01'); Query OK, 1 row affected (0.40 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-------+---------------+ | Id | Name | AdmissionDate | +----+-------+---------------+ | 1 | Chris | 2019-11-21 | | 2 | Mike | 2019-03-11 | | 3 | Sam | 2018-04-01 | | 4 | Carol | 2019-05-01 | +----+-------+---------------+ 4 rows in set (0.00 sec)
Let us now update the table on the basis of a specific DATE value i.e. 2019-04-01 here −
mysql> update DemoTable set Name='Robert',AdmissionDate='2019-04-01' where Id=3; Query OK, 1 row affected (0.14 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 | AdmissionDate | +----+--------+---------------+ | 1 | Chris | 2019-11-21 | | 2 | Mike | 2019-03-11 | | 3 | Robert | 2019-04-01 | | 4 | Carol | 2019-05-01 | +----+--------+---------------+ 4 rows in set (0.00 sec)
- Related Articles
- Update a column based on another MySQL table’s column
- MySQL DATE_ADD() to increment a date based on the value in another column?
- Concatenate rows on the basis of boolean values in another column with MySQL
- Search records on the basis of date in MySQL?
- Perform multiplication in SELECT depending on column value in MySQL?
- Update only a single column in a MySQL table and increment on the basis of a condition
- Select items based on value first, then order on the basis of date for rest of the records in MySQL
- Update MySQL table column by matching date using date() function?
- MySQL query to fetch only a single field on the basis of boolean value in another field
- Exclude rows based on column value when another duplicate column value is found in MySQL?
- Match column values on the basis of the other two column values in MySQL
- How to update a MySQL date type column?
- Update record on a specific date matching the current date in MySQL
- Get first date from timestamp in MySQL group by another column with duplicate value
- Update only a single column value in MySQL

Advertisements