Let's assume we would like to clear all notes for
given user. So we will use subquery lookup user_key
and then update all the notes for given user. Examine
following query:
update notes
set no_text = null
and no_text is not null
where no_key in (
select no_key from notes
where user_key in (
select user_key from users
where user_name = 'user3'
)
);
The above query could be run multiple time but only
once it would update some data. See the part with
no_text is not null. That would prevent updates on
the next run despite all the given rows would be
already empty (or null).
Result of the table notes after this part would be
following:
select
n.user_key,
n.no_key,
n.no_text
from notes n
order by user_key, no_key;