Moving data from one table to another using mysql query

Discussion in 'MySQL' started by computerzworld, Aug 28, 2008.

  1. #1
    Hello Experts,
    I am having two tables and I want to move the data from one table to another using mysql query. All the fields of first table(from which I want to move data) are in second table and two extra fields are there. I want to move the data of first table to second table when certain condition is satisfied. So, I have written query like,

    insert into table2('field1','field2','field3','field4','field5') select 'field1','field2','field3' from table1 where 'field1'<1,'field4 value','field5 value';


    But it gave me error when I ran it.. What exactly I want to do is to insert all the values of first table into second one and two extra fields that are present in the second table. But I am not able to insert. Please help me if anybody have solution of this. Thanks in advance.
     
    computerzworld, Aug 28, 2008 IP
  2. CreativeClans

    CreativeClans Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    INSERT INTO table2
    SELECT 
      field1,
      field2,
      field3,
      'value4',
      'value5'
    FROM table1 
    WHERE field1 < 1
    Code (markup):
     
    CreativeClans, Aug 29, 2008 IP
  3. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    thanks for ur reply... my problem solved....
     
    computerzworld, Aug 29, 2008 IP