-3

This is a Firebird database.

First Table

Contacts Company_ID - job_title

Second Table

Client_id - Co_name

In contacts, I want to the job_title field to contain the co_name.

client_id and company_id are the same. Co_name correspond to company_id as well as client_id.

this:

UPDATE Contacts
SET Contacts.Job_title = Clients.co_name
WHERE
    company_id IN (
        SELECT
            client_id
        FROM
            clients
        JOIN Contacts c ON Client_id = company_id
        WHERE
            record_status = 'A'
    )

gives me an error as cannot find (clients.co_name)

this other option:

UPDATE Contacts
JOIN Clients ON Clients.Client_id = Contacts.Client_id
SET Contacts.Job_title = Clients.Client_name

gives me an error on JOIN

Any other ideas please?

Thank you all

mitkosoft
  • 5,262
  • 1
  • 13
  • 31
L_GIB
  • 125
  • 7

1 Answers1

0

Possibly already answered here: Update records in one table using another table's records as WHERE parameters - looks like it should work, but I'm not a Firebird expert.

The code from that answer (but look for more context, and alternative answers):

UPDATE Table1
SET Column1 = NULL
WHERE NOT EXISTS 
    (SELECT 1 
    FROM Table2 
    WHERE Table2.Column2 = Table1.Column2)

(couldn't flag question as duplicate because that question has no upvoted or accepted answer)

Community
  • 1
  • 1
pete the pagan-gerbil
  • 3,136
  • 2
  • 28
  • 49