Reputation: 1646
I'm trying to write an SQL statement that duplicates all rows WHERE employee = 16
(i.e.), but the new rows would have a different employee
value.
Table before INSERT
:
| employee | property_name | property_value |
|:--------:|:--------------|:---------------|
| 16 | Salary | 28,000 |
| 16 | Department | 12 |
| 17 | Salary | 38,000 |
| 17 | Department | 8 |
Desired outcome after INSERT
:
| employee | property_name | property_value |
|:--------:|:--------------|:---------------|
| 16 | Salary | 28,000 |
| 16 | Department | 12 |
| 17 | Salary | 38,000 |
| 17 | Department | 8 |
| 18 | Salary | 28,000 |
| 18 | Department | 12 |
I've seen some threads that use variables. Could I set and reference a variable somehow that would replace values from an insert/select?
The answer to this thread looks like it would work. But I'd rather not create and drop tables like that.
Upvotes: 1
Views: 61
Reputation: 120937
insert into YourTable (employee,property_name, property_value)
select 18, property_name, property_value from YourTable where employee = 16
Upvotes: 4