I WANT TO DO SOMETHING LIKE THIS:
CREATE TRIGGER addwinner AFTER INSERT ON bids
FOR EACH ROW BEGIN
IF exists(select * from wins as LT where LT.item_index=NEW.item_index) THEN
SELECT item_index, MIN( bid_amount )
FROM update_winnerslist AS a1
WHERE a1.item_index = NEW.item_index;
UPDATE wins SET email_id=NEW.emai_id, bid_amount=a1.bid_amount where wins.item_index=a1.item_index;
END IF;
END;
Basically what i want is to update a table using another table’s tuple by comparing certain attributes.
As explained in the manual, when defining procedures/triggers/etc. that use
;within their body to separate commands, you need to define an alternate delimiter in order that theCREATEcommand is interpreted as a single statement.To
UPDATEwith the results of theSELECT, like you describe, you can do any of:Save the result of the
SELECTin a variable which you then use in theUPDATE:Just use a subquery (so long as it doesn’t reference the table you’re updating):
Or just join the tables: