
- 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
Set particular value of column without using update and while inserting values in MySQL
Here, we will see an example wherein we are inserting dates and updating them while using the INSERT query.
Let us first create a table −
mysql> create table DemoTable816(DueDate datetime); Query OK, 0 rows affected (0.45 sec)
Insert some records in the table using the insert command. Here is the query to add (minutes/hours/days/months/ years) to date when performing INSERT −
mysql> insert into DemoTable816 values(date_add(now(),interval 3 minute)); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable816 values(date_add('2018-01-21 00:00:00',interval 3 Hour)); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable816 values(date_add('2016-11-11 12:40:00',interval 3 Day)); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable816 values(date_add('2018-12-01 11:00:00',interval 3 Month)); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable816 values(date_add('2011-03-21 10:00:00',interval 3 Year)); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable816;
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-08-03 13:08:43 | | 2018-01-21 03:00:00 | | 2016-11-14 12:40:00 | | 2019-03-01 11:00:00 | | 2014-03-21 10:00:00 | +---------------------+ 5 rows in set (0.00 sec)
- Related Articles
- Update the date and time values while inserting them in MySQL
- Can we skip a column name while inserting values in MySQL?
- Set conditions while adding column values in MySQL?
- Update column data without using temporary tables in MySQL?
- How to update a column with the same values (not all) using UPDATE, SET and LIMIT in MySQL?
- MySQL UPDATE column names and set None values with N/A?
- How to update all the entries except a single value in a particular column using MySQL?
- How can we update MySQL table after removing a particular string from the values of column?
- How to convert positive value to negative while inserting in MySQL?
- How to add column values in MySQL without using aggregate function?
- Inserting multiple parameter values into a single column with MySQL?
- Update a column in MySQL and remove the trailing underscore values
- Update only a single column value in MySQL
- Format date while inserting records in MySQL
- Count number of times value appears in particular column in MySQL?

Advertisements