I am trying to update certain pieces of data based on a select statement within a trigger. The select statement is as follows:
SELECT col1
FROM tbl1 d
LEFT OUTER JOIN tbl2 e ON D.colid = E.colid
I then want to change the data returned from this statement to a new value calculated in the trigger. I thought it might be something like this e.col1 = COUNTER but that doesn’t seem to work. Any help with updating this data would be great, thanks.
EDIT: I’ve changed the select query to retrieve the data I actually want. The one I stated above was wrong.
UPDATE tbl2 SET col1 = COUNTER
WHERE EXISTS(SELECT col1
FROM tbl1 d
LEFT OUTER JOIN tbl2 e ON D.colid = E.colid
WHERE col2= :new.col2);
I should state again that the problem is when using the code above is that the whole column in the table is updated as opposed to the data returned by the select query.
EDIT:
tbl1 contains columns colid, col2 and
tbl2 contains columns colid, col1
Trigger is before insert on tbl1.
It would help if you’d told us which table the trigger was on, what kind of trigger, and what columns are in what table. I still can’t quite figure out what you’re trying to do with these updates.
I think the problem is that you are doing a
LEFT JOINin your inner select statement. Since there will always be a row in the inner query and you’re doing this in anEXISTSclause, it will always match a row, and yourUPDATEwill fire on every row in the table.Maybe this will work better for you:
I will say that if this trigger is on tbl2, then this is a bad way of doing this, because you’re likely to run into the mutating table problem.