snippetsqlMinor
How to copy data into same table based on existing data in sql?
Viewed 0 times
samesqlintobasedhowexistingdatatablecopy
Problem
It is possible to copy a set of rows based on Date column and insert in same table with different date?
For example : I have 5 rows with Date column value '201839'
I need to copy those 5 rows in '201840' as well as '201841'
Or can we create a view that have a copy of 201839 rows as 201840 in sql.
For example : I have 5 rows with Date column value '201839'
I need to copy those 5 rows in '201840' as well as '201841'
Or can we create a view that have a copy of 201839 rows as 201840 in sql.
Solution
One more solution is to run sub query for two time with different updated Date_column value. It will select data from same table and updated with different date_value.
INSERT into TABLE_NAME (Column1, Column2, Date_column)( SELECT (Column1, Column2, '201840') FROM TABLE_NAME where Date_column = '201839');
INSERT into TABLE_NAME (Column1, Column2, Date_column)( SELECT (Column1, Column2, '201841') FROM TABLE_NAME where Date_column = '201839');Code Snippets
INSERT into TABLE_NAME (Column1, Column2, Date_column)( SELECT (Column1, Column2, '201840') FROM TABLE_NAME where Date_column = '201839');
INSERT into TABLE_NAME (Column1, Column2, Date_column)( SELECT (Column1, Column2, '201841') FROM TABLE_NAME where Date_column = '201839');Context
StackExchange Database Administrators Q#236747, answer score: 3
Revisions (0)
No revisions yet.