Insert rows into MySQL table while changing one value

Posted by Jonathan on Stack Overflow See other posts from Stack Overflow or by Jonathan
Published on 2010-03-18T22:23:10Z Indexed on 2010/03/18 22:31 UTC
Read the original article Hit count: 360

Filed under:
|

Hey all-

I have a MySQL table that defines values for a specific customer type.

| CustomerType | Key Field 1 | Key Field 2 | Value |

Each customer type has 10 values associated with it (based on the other two key fields).

I am creating a new customer type (TypeB) that is exactly the same as another customer type (TypeA). I want to insert "TypeB" as the CustomerType but then just copy the values from TypeA's rows for the other three fields.

Is there an SQL insert statement to make this happen?

Somthing like:

insert into customers(customer_type, key1, key2, value)  values
"TypeB" union 
    select key1, key2, value
    from customers
    where customer_type = "TypeA"

Thanks- Jonathan

© Stack Overflow or respective owner

Related posts about mysql

Related posts about insert