• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

SQL Batch Copy/Insert

Hello Experts!

I need some help...

I have a database which has a table called 'clients'. Each 'client' has an 'address' column containing their address. There now exists a second column called 'invoice_address' as many of our clients have a different Invoice address. I have roughly 400 client records. To make matters easier I would like to copy the current address of each, as the default for the invoice address and then change only those that differ manually.

So essentially I need a query that would allow me to copy one column of data to another, within the same table, for each record. Can this be achieved with a single SQL statement?

I hope I have expressed the scenario clearly and that someone can help. I am on standby to answer any questions.

Many Thanks.

P.S - My Database is MySQL and supports a custom PHP intranet system. DBMS is phpMyAdmin.
1 Solution
Beverley PortlockCommented:
Make a backup of your table before doing any of this or work on a copy.

The single SQL statement will be along these lines

UPDATE clients
    SET invoice_address = address
    WHERE invoice_address <> address

The chances are that your MySQL installation will be case-insensitive in the comparison so that "Fred" will be equal to "fred".

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now