Results 1 to 5 of 5

Thread: SQL Query For Copy records from one table to another

  1. #1
    Join Date
    Dec 2008
    Posts
    9

    SQL Query For Copy records from one table to another

    Hi,
    I need some help,
    Can anyone tell how to copy records from one table to another table by using SQL Query.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,949

    Re: SQL Query For Copy records from one table to another

    If you want to create a single, new table with all the records (rather than overwriting one of the existing tables):

    SELECT * FROM Table1OfPC1 ;
    UNION ;
    SELECT * FROM Table1OfPC2 ;
    UNION ;
    SELECT * FROM Table1OfPC3 ;
    INTO TABLE NewTable1

  3. #3
    Join Date
    May 2008
    Posts
    2,015

    Copy Unique Records from one Table to Another Table

    You can use the following query.

    Code:
    insert into newtablename select * from oldtablename

    But if you want to Copy only Unique Records from one Table to Another Table
    then use this query.

    Code:
    insert into newtablename select distinct * from oldtablename

  4. #4
    Join Date
    Dec 2008
    Posts
    7

    Re: SQL Query For Copy records from one table to another

    Hi,

    Very nice piece of code.
    Short and simple to understand.
    Thanks for sharing your knowledge with us.

    Keep posting.

  5. #5
    Join Date
    May 2010
    Posts
    1

    Re: Copy Unique Records from one Table to Another Table

    Quote Originally Posted by Katty View Post
    You can use the following query.

    Code:
    insert into newtablename select * from oldtablename

    But if you want to Copy only Unique Records from one Table to Another Table
    then use this query.

    Code:
    insert into newtablename select distinct * from oldtablename


    This is very simple & good idea to copy records from 1 table to another which is already existing Thank You.

Similar Threads

  1. PHP mysql select unique records from one table
    By Captain Carrot in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 12:18 PM
  2. Select unique records from a table
    By Conraad in forum Software Development
    Replies: 5
    Last Post: 13-05-2010, 12:01 AM
  3. Query to find out duplicate records
    By Shophia_D in forum Software Development
    Replies: 5
    Last Post: 22-12-2009, 10:03 AM
  4. Unable to delete records from Two Joined table
    By Broot in forum Software Development
    Replies: 3
    Last Post: 22-09-2009, 03:44 PM
  5. Replies: 3
    Last Post: 08-08-2009, 11:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •