Professional Web Applications Themes

how I copy a column betwen tables mysql? - MySQL

I have "tableA" with column "a" and "tableB" with column "b". Column "a"has new material so i need to copy the info from tableA column "a" in to tableB column "b", tableB is empty so i can't say where tableA.id = TableB.id waht can i do? please help please help. give examples i am a newbe this is mysql thank you...

  1. #1

    Default how I copy a column betwen tables mysql?

    I have "tableA" with column "a" and "tableB" with column "b".

    Column "a"has new material so i need to copy the info from tableA
    column "a" in to tableB column "b", tableB is empty so i can't say
    where tableA.id = TableB.id
    waht can i do? please help
    please help. give examples i am a newbe

    this is mysql

    thank you

    fhelik Guest

  2. #2

    Default Re: how I copy a column betwen tables mysql?


    fhelik wrote: 


    Hi

    one approach.. The table is empty instead you can create a new one.
    ex:
    mysql> create table a (aa integer);
    Query OK, 0 rows affected (0.12 sec)

    mysql> insert into a values(1);
    Query OK, 1 row affected (0.00 sec)

    mysql> create table b as select * from a;
    Query OK, 1 row affected (0.07 sec)
    Records: 1 Duplicates: 0 Warnings: 0

    mysql> select * from b
    -> ;
    +------+
    | aa |
    +------+
    | 1 |
    +------+
    1 row in set (0.00 sec)

    If you want a different name for the table "b"
    try this

    mysql> create table c as select aa bb from a;
    Query OK, 1 row affected (0.06 sec)
    Records: 1 Duplicates: 0 Warnings: 0

    mysql> select * from c;
    +------+
    | bb |
    +------+
    | 1 |
    +------+
    1 row in set (0.00 sec)


    Thanks
    Devi

    Devi Guest

  3. #3

    Default Re: how I copy a column betwen tables mysql?

    Hi,
    Your solution is to create a new table and copy something from old
    table. how about this case:
    table a and table b both has column c1,c2 and c3, now I need copy
    record from a to b when I find one which has c1 value is "abc" in table
    a. I can do it like this:
    run "select c1,c2,c3 from a where c1=abc" firstly, get the values, then
    "insert to b (`c1`,`c2`,`c3`) values ($values)".
    but, in the future, the table structure maybe will change(add one
    column or delete one column), then this code needs be changed as well.
    Is there a way to ignore the exact table structure? just copy the total
    records to another table which has same structure? then we don't need
    change code when table structure changed.

    Thanks.


    Devi wrote: 
    >
    >
    > Hi
    >
    > one approach.. The table is empty instead you can create a new one.
    > ex:
    > mysql> create table a (aa integer);
    > Query OK, 0 rows affected (0.12 sec)
    >
    > mysql> insert into a values(1);
    > Query OK, 1 row affected (0.00 sec)
    >
    > mysql> create table b as select * from a;
    > Query OK, 1 row affected (0.07 sec)
    > Records: 1 Duplicates: 0 Warnings: 0
    >
    > mysql> select * from b
    > -> ;
    > +------+
    > | aa |
    > +------+
    > | 1 |
    > +------+
    > 1 row in set (0.00 sec)
    >
    > If you want a different name for the table "b"
    > try this
    >
    > mysql> create table c as select aa bb from a;
    > Query OK, 1 row affected (0.06 sec)
    > Records: 1 Duplicates: 0 Warnings: 0
    >
    > mysql> select * from c;
    > +------+
    > | bb |
    > +------+
    > | 1 |
    > +------+
    > 1 row in set (0.00 sec)
    >
    >
    > Thanks
    > Devi[/ref]

    Hans Guest

  4. #4

    Default Re: how I copy a column betwen tables mysql?

    In article <googlegroups.com>, Hans
    says... 

    INSERT INTO b
    SELECT * FROM a
    WHERE c1 = abc;
    --
    PleegWat
    Remove caps to reply
    PleegWat Guest

  5. #5

    Default Re: how I copy a column betwen tables mysql?

    this is a better solution

    PleegWat wrote: 
    >
    > INSERT INTO b
    > SELECT * FROM a
    > WHERE c1 = abc;
    > --
    > PleegWat
    > Remove caps to reply[/ref]

    Devi Guest

Similar Threads

  1. MySQL Copy Row
    By dogManifesto in forum PHP Development
    Replies: 1
    Last Post: April 10th, 04:45 PM
  2. Tables...Copy/Paste from Word
    By Gunjani in forum Web Design
    Replies: 0
    Last Post: December 4th, 12:45 PM
  3. Query betwen IDS731-Solaris and IDS940Linux
    By Jordi Tous in forum Informix
    Replies: 4
    Last Post: September 22nd, 09:19 PM
  4. File download behavior different betwen Netscape/IE
    By Alexander Gilman Carver in forum PHP Development
    Replies: 4
    Last Post: September 13th, 05:12 PM
  5. Replies: 2
    Last Post: August 17th, 01:34 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139