Rain
Rain

Reputation: 259

Copy one row to another column in same table

There's the table where CUSTOMERS that are recognized by unique ID values, all records in this table also have CONSENT boolean attributes.

I need to copy those CONSENT values to CONSENT2 boolean fields for the same records.

As far as I know, there are several SQL commands that are disabled on this server.

Would this work?

UPDATE
    CUSTOMERS
SET
    CUSTOMERS_A.CONSENT_Email = CUSTOMERS_A.CONSENT_Email2
    CUSTOMERS_A.CONSENT_Phone = CUSTOMERS_A.CONSENT_Phone2
FROM
    CUSTOMERS AS CUSTOMERS_A
    INNER JOIN CUSTOMERS AS CUSTOMERS_B
        ON CUSTOMERS_A.id = CUSTOMERS_B.id

Upvotes: 0

Views: 45

Answers (2)

user8406805
user8406805

Reputation:

You can simply use, Don't add extra join/condition until really that required.

UPDATE CUSTOMERS
   SET (CONSENT_Email2,CONSENT_Phone2) = (CONSENT_Email,CONSENT_Phone);

It will copy the CONSENT2 values for both of columns into CONSENT.

i.e. CONSENT >>> CONSENT2

Upvotes: 1

ScaisEdge
ScaisEdge

Reputation: 133400

You can do without join

UPDATE
CUSTOMERS
   SET CONSENT_Email = CONSENT_Email2,
       CONSENT_Phone = CONSENT_Phone2

Upvotes: 1

Related Questions