I have a database where I need to update the data on some table based on another table's registries. Could I get help as in how to do it since I'm a bit stuck with it.
I have this select query as reference:
select i.*
from transaction as 't'
inner join transaction_detail as 'td'
on t.id_transaction=td.id_transaction
inner join inventory as 'i'
on i.id_inventory=td.id_inventory
where t.registered_date>='2016-09-01';
And what I want to do is update one field from the table i based on a date from table t, so it would go something like this:
update inventory i
set i.status='cancel'
from transaction_detail td
inner join transaction t
on t.id_transaction=td.id_transaction
where t.registered_date>='2016-09-01'
and i.id_inventory=td.id_inventory;
I'm doing this on postgres, any pointers? Should I try doing this with a function?
EDIT: If it helps at all, relations between columns are one to many from transaction to transaction_detail and one to one from transaction_detail to inventory.