How do you copy one field to another - copy NOT move?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do you copy one field to another - copy NOT move?

Post by simonmlewis »

I want to copy the contents of one field in all rows, to another field. ie. Category to be copied into Catname.

I have tried this:

Code: Select all

UPDATE [yourTable] SET `cost` = `salesprice`;
But all it does is to MOVE it. Category ended up empty!!

What's the method??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: How do you copy one field to another - copy NOT move?

Post by mikosiko »

:?: :?: MOVE :?: :?:

Code: Select all

UPDATE [yourTable] SET `catname` = `category`;
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you copy one field to another - copy NOT move?

Post by simonmlewis »

UPDATED: APOLOGIES: your code is the other way around. I did it the wrong way didn't I. WILL TRY NOW.

Sorry but as my original post states, that code MOVES the data to the other field, it does not COPY it.

I need to copy it - so the same contents are in TWO fields.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you copy one field to another - copy NOT move?

Post by simonmlewis »

Bingo thanks.
Logical really. Durr!!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply