[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


SQL Batch Copy/Insert

Posted on 2008-11-20
Medium Priority
Last Modified: 2013-12-13
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.
Question by:MariusGM
1 Comment
LVL 34

Accepted Solution

Beverley Portlock earned 2000 total points
ID: 23003436
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".


Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question