transfer the columns of one table into another table with condition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudhakaranr
    New Member
    • Dec 2006
    • 24

    transfer the columns of one table into another table with condition

    hi all,

    In table1, i have 6 columns and in table2, i have 10 columns.
    i want to transfer 5 columns from table2 to table1 with the condition.

    the condition is..

    both the tables have primarykey, if the primary key in table1 matches with table2's primarykey, then we should trafer the selected column in to table1 from table2.

    I want a query for the above..

    Please help me in this...

    Thanks in advance.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    From the depth and scope of your questions I have the distinct feeling that you do not know very much about SQL. Maybe it is a good idea to get some education and follow a few starter's tutorials. For now I will help you out, but the next time you show some of your code here with which we will, of course, help you. But the idea of this forum is to have programmers help programmers, not by supplying code but by providing assistance.
    Code:
    UPDATE table2 as t2, table1 as t1 
      SET 
        t2.col1=t1.col1, 
        t2.col2=t1.col2,
        t2.col3=t1.col3,
        t2.col4=t1.col4,
        t2.col5=t1.col5,
      WHERE t2.keycol = t1.keycol
    Ronald :cool:

    Comment

    • sudhakaranr
      New Member
      • Dec 2006
      • 24

      #3
      Hi thanks for the query...

      I already mentioned that i am newly started to program...
      I have already started to study PHP-MySQL.
      I tried that but I couldn't.
      Next time defenitly, i will come with my code...
      thanks...

      Comment

      Working...