Mysql
 sql >> Base de données >  >> RDS >> Mysql

MYSQL - Jointure interne avec AFTER UPDATE dans la table

D'après les commentaires, il semble que vous ayez simplement besoin d'une Inner Join entre le jobPost et users tableau, sur emailTeacher .

Aussi, certaines colonnes de Select manquaient, par rapport à Insert clause; Je les ai ajoutés dans le bon ordre.

DELIMITER //
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, 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.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;
END //
DELIMITER ;