I'm stuck with an UPDATE
. My tables originally were:
Clients
------------------
ID
Emails
Notification_type
Contracts
------------------
ID
Client_id (FK)
Contracts_document_types
------------------
Contract_id (FK)
Document_type_id (FK)
And I could notify basing on Clients
table. Then I had to change the notification method. My database changed to:
Contracts_document_types
------------------
Contract_id (FK)
Document_type_id (FK)
Notification_method_id (FK)
Notification_methods
------------------
ID
emails
notification_type
I was able to create the necessary notification_methods
entries based on clients, but I didn't find a way to associate in contracts_document_types.notification_method_id
. It is possible to find the notification_method
based on clients
table, but the table to be updated is contracts_document_types
and I cannot figure out how.
My idea is something like:
update contracts_document_types
set notification_method_id = query.nm_id
from ( select NM.id as nm_id from notification_methods NM
inner join clients C on C.emails = NM.emails
and C.notification_type = NM.notification_type
) as query
where ????????
It's possible to get to contracts_document_types
from clients
(where the information lies), but I could not associate them to the right users. I'm missing something important about the iteration process in UPDATE FROM
statement.
Resume: 1 client has many contracts_document_types, I have an notification_method created based on clients. I cannot find a way to put the right notification_method on each client (all contracts_document_types from that client).