I'm a pretty new database student...
I have two tables. User, and Trip.
Whenever a new Trip is added to the database, I want it to trigger an update on the User table in the "totalMiles" column. I want it to take the Trip.userID and change the value in the "totalMiles" column of only the user with the same User.userID as the Trip.userID entry.
I want it to take the sum from "tripMiles" where the Trip.userID = User.userID. userID is a foreign key in the Trip table from the User table.
right now I just have:
CREATE DEFINER='root'@'localhost'TRIGGER 'DATABASE'.'Trip_AFTER_INSERT'
AFTER INSERT ON 'Trip' FOR EACH ROW
BEGIN
UPDATE User
SET totalMiles=sum(tripMiles)
WHERE Trip.userID = User.userID;
END
The error I get is "unknown column 'Trip.userID' in 'where clause'.
I googled and searched through a couple of posts here but I didn't really find anything.