knight944
knight944

Reputation: 21

Duplicating Rows in SQL

I am trying to select all rows of table A and then duplicate all the rows in Table A while changing 1 field. Please find an example below along with the code I already wrote.

SELECT COLA, COLB, COLB
FROM TABLE A. 

I want my end result to look like the following...

COLA     COLB     COLC
1234     test     01
1234     test     02
9876     testing  01
9876     testing  02

Upvotes: 0

Views: 51

Answers (1)

Perfect Square
Perfect Square

Reputation: 1418

Something like this should work:

INSERT INTO A (COLA, COLB, COLC)
SELECT
    COLA, 'testing', COLC
FROM A

I assume that you wanted to change column B from 'test' to 'testing'. If COLA is your primary, autoincremented key than just put NULL instead of COLA in SELECT to avoid duplicated keys.

Upvotes: 1

Related Questions