Couple of things:
the "after insert" and "If (inserting)" are redundent. Remove the "If (inserting)" it's unnecessary since your trigger is limited to AFTER INSERT. Just adds more code to read.
It seems you are trying lower your inventory when something is sold. I don't see that you actually do that.
This is embeded query doesn't have a key associated with it. (This is were your error message comes from).
select i.quantity
from inventory i, concessions_sold cs, concession c
where i.inventory_id = c.inventory_id and c.concession_id = cs.concession_id
- You don't have a where clause and your inline-select doesn't limit the rows coming back from the inventory table. If you do get this to work, you are going to update every row in your Inventory table.
To make your actual update clause work.
UPDATE (
SELECT **i.inventory_id**, i.quantity
FROM Inventory i
, Concessions_sold cs
, Concessions c
WHERE i.inventory_id = c.inventory_id
AND c.concession_id = **:NEW.concession_id**
)
SET quantity = :new.quantity
Now it works there are a few problems:
1. Linking table is unnecessary.
2. The inline SQL is making this UPDATE statement more difficult to read and hence more difficult to modify in the future.
I would be much more explicit:
UPDATE Inventory
SET quatity = quanaity - :new.quanity
WHERE inventory_id IN (
SELECT inventory_id
FROM Conessions c
JOIN c.concession_id = :NEW.concession_id
)
Obviously there's no checks to see that inventory quantity actually exists, something else you might want to take into consideration.
So your new trigger would look like this.
CREATE or REPLACE TRIGGER LabEx5_1 AFTER INSERT ON Concessions_sold
FOR EACH ROW
BEGIN
UPDATE Inventory
SET quatity = quanaity - :NEW.quanity
WHERE inventory_id IN (
SELECT inventory_id
FROM Conessions c
JOIN c.concession_id = :NEW.concession_id
);
END LabEx5_1;