我的jobspost表中有一个触发器,它在更新jobstatus&emailteacher列后触发。触发器插入与emailteacher匹配的所有行,并插入到名为jobrequests的新表中。
我的问题是-当更新一行时,具有相同emailteacher的所有行都会插入到新表中。我只想插入已更新的受影响行。我在下面附上了sql。谢谢您。谢谢你的帮助。
CREATE DEFINER=`root`@`localhost` TRIGGER
trg_jobPost_after_update
AFTER UPDATE ON jobPost
FOR EACH ROW
BEGIN
-- Check if jobStatus is Updated (then only we Insert)
IF ( OLD.jobStatus <> NEW.jobStatus AND OLD.emailTeacher <> NEW.emailTeacher) THEN
INSERT INTO jobRequest (userID, name, email, phoneNo,
location, lat, lng, jobID, title, level,
dateFrom, dateTo, description,
jobStatus, emailTeacher, nameTeacher,
locationTeacher, phoneNoTeacher, cv,
gardavetting, linkedin)
SELECT
jobPost.userID
, jobPost.name
, jobPost.email
, jobPost.phoneNo
, jobPost.location
, jobPost.lat
, jobPost.lng
, jobPost.jobID
, jobPost.title
, jobPost.level
, jobPost.dateFrom
, jobPost.dateTo
, jobPost.description
, NEW.jobStatus
, NEW.emailTeacher
, users.nameTeacher
, users.locationTeacher
, users.phoneNoTeacher
, users.cv
, users.gardavetting
, users.linkedin
FROM jobPost
JOIN users ON users.emailTeacher = jobPost.emailTeacher
WHERE jobPost.emailTeacher = NEW.emailTeacher;
END IF;
结束
暂无答案!
目前还没有任何答案,快来回答吧!