SQL Batch Copy/Insert

Posted on 2008-11-20
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

    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

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now