Tags

, , , , , ,



— Copy all the values from one column to another column in table ( PAWAN)

–Create a table
CREATE TABLE CopyColumns
(

    Name varchar(50) NOT NULL,
    Address varchar(70) NOT NULL,
    CopyAddress varchar(70) NULL

)

–Insert the values
INSERT INTO CopyColumns ( Name , Address )
VALUES ( ‘Pawan’  ,  ‘Pune ‘)

INSERT INTO CopyColumns ( Name , Address )
VALUES ( ‘Gauri’  ,  ‘A  Nagar ‘)

INSERT INTO CopyColumns ( Name , Address )
VALUES ( ‘Saurabh’  ,  ‘A Nagar ‘)

INSERT INTO CopyColumns ( Name , Address )
VALUES ( ‘Himanshu’  ,  ‘Padmavati ‘)

INSERT INTO CopyColumns ( Name , Address )
VALUES ( ‘Rahul W’  ,  ‘ Jordan’)


— Use the below query to copy all the data from Address to CopyAddress column
UPDATE CopyColumns SET CopyAddress = ( SELECT Address FROM CopyColumns C1 WHERE C1.Name = CopyColumns.Name )

–Check
SELECT Name , Address , CopyAddress from CopyColumns
___________
Pawan Kumar
pawankkmr@hotmail.com

Advertisements