SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update one table using another

    Hi
    im using the below to update a field in one table using records from another
    but all im getting it this error

    Unknown column 'INVOICE_Number.invoiceold' in 'where clause'

    can anyone help me out?
    here the query:

    Code:
    UPDATE `TEST`.`invoiceold`
    SET CUSTOMER_AccNum .`invoiceold` = CUSTOMER_AccNum .`invoice`
    WHERE INVOICE_Number .`invoiceold` = INVOICE_Number .`invoice`
    AND COMPANY_Number .`invoiceold` = COMPANY_Number .`invoice`
    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,015
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    updating one table from another requires a join

    also, your column syntax is wrong, it should be tablename.columnname, not columnname.tablename
    Code:
    UPDATE invoiceold
    INNER
      JOIN invoice
        ON invoice.INVOICE_Number = invoiceold.INVOICE_Number
       AND invoice.COMPANY_Number = invoiceold.COMPANY_Number 
    SET    invoiceold.CUSTOMER_AccNum = invoice.CUSTOMER_AccNum
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi r937

    Thanks that worked perfect


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
  •