SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Transfer fields

  1. #1
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Transfer fields

    I have to tables that are identical "Invoices" and "PostedInvoices".
    Is there any mysql-command that easily copies a record from one table to the other table?

  2. #2
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will add all data from one to the other...
    Code:
    INSERT INTO PostedInvoices
    SELECT * 
    FROM Invoices
    Lats...

  3. #3
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thx for your reply.
    When I try to do this I get this error:

    "
    Database error: Invalid SQL: INSERT INTO PostedInvoices VALUES ('SELECT * FROM Invoices WHERE idInvoice=1')
    MySQL Error: 1136 (Column count doesn't match value count at row 1)
    Session halted.
    "

  4. #4
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That error indicates that the tables are not the same - perhaps one of them has an extra field??
    Lats...

  5. #5
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    To make sure that they are identical I just deleted the structur for PostedInvoices, and copied it from Invoices.

    But I still get the same error message.

  6. #6
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this...
    Code:
    INSERT INTO PostedInvoices
    SELECT * 
    FROM Invoices
    WHERE idInvoice=1
    Nothing else
    Lats...

  7. #7
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thx! That did the trick.

    But now I suddenly realise that I do not want to copy the 'idInvoice'-field, because the idInvoice-series will not be the same for Invoices and PostedInvoices.

    Is there any way to SELECT * EXCEPT idInvoice?

  8. #8
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, try this...
    Code:
    INSERT INTO PostedInvoices (field1, field2, field3)
    SELECT field1, field2, field3
    FROM Invoices
    Lats...

  9. #9
    SitePoint Addict
    Join Date
    Feb 2004
    Posts
    291
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That also did the trick!

    Thx for your patience.

  10. #10
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Great news
    Lats...


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
  •