I use Firebird 3.0 and I have 3 tables:
Table1: tbl1_id (PK), f2_id (FK), tbl1_f1
tbl1_f2 is a foreign key to table2
Table2: f2_id (PK), f3_id (FK)
f3_id is a foreign key to table3
Table3: f3_id (PK), tbl3_code
Now I need to set Table1.tbl1_f1 = 1 where Table3.tbl3_code = 'value' so I wrote this SQL:
update table1 set tbl1_f1 = 1 where (tbl1_f1 is null)
and table1.tbl1_id in (
select
tbl1_id
from table1
inner join Table2 on (Table1.f2_id = Table2.f2_id)
inner join Table3 on (Table2.f3_id = Table3.f3_id)
where (Table3.tbl3_code = 'value')
)
Is my update SQL correct or there is better way to write it ?