Athreya Sridhar
Athreya Sridhar

Reputation: 39

Copying Data from one table to another with updated date

I've two tables 2017_11_08_minute and 2017_11_09_minute. My 2017_11_08_minute table is empty. I need to copy all the data from 2017_11_09_minute to 2017_11_08_minute.

I've a DATETIME column in my 2017_11_09_minute which has data like 2017-11-09 00:00:20

I need to update this to 2017-11-08 00:00:20 while copying the rest of the data as it is!

Upvotes: 0

Views: 1488

Answers (1)

Ullas
Ullas

Reputation: 11556

If you want to reduce 1 day from the date column value then use DATE_SUB function.

Query

insert into `2017_11_08_minute`(`col_1`, `col_2`, `col_2`)
select `col_1`, `col_2`, date_sub(`date_col`, interval 1 day)
from `2017_11_09_minute`;

Or we can use even DATE_ADD

Query

insert into `2017_11_08_minute`(`col_1`, `col_2`, `col_2`)
select `col_1`, `col_2`, date_add(`date_col`, interval -1 day)
from `2017_11_09_minute`;

Upvotes: 1

Related Questions