Reputation: 618
I need to duplicate a row in SQL, update one column in the old row and update one column in the new row.
Using MariaDB/MySQL
id | attribute | value | start_date | end_date |
---|---|---|---|---|
1 | attribute_x | 0 | 0 | null |
2 | attribute_y | 1 | 0 | null |
I want to:
Upvotes: 0
Views: 134
Reputation: 1271091
This is two operations:
update t
set end_date = now()
where attribute = 'attribute_x';
insert into t (attribute, value, start_date, end_date)
select attribute, value, now(), null
from t
where attribute = 'attribute_x';
Upvotes: 1