-- -----------------------------------------------
--  Find and registrer historically approved users
-- -----------------------------------------------
INSERT IGNORE INTO sod_approved_user (risk_id, username, `system`, client)
	SELECT 
		sod_preventive_check_violation.rule_id, 
		sod_preventive_check_violation.username, 
        sod_preventive_check_violation.system, 
        sod_preventive_check_violation.client
	FROM sod_preventive_check_violation
	WHERE sod_preventive_check_violation.handle IN(SELECT handle FROM sod_preventive_check_wf_approval WHERE action = 'approved') AND 
		 sod_preventive_check_violation.rule_id IN(SELECT id FROM sod_rule) AND
		 sod_preventive_check_violation.warning_id = 4;

INSERT IGNORE INTO sod_approved_user (risk_id, username, `system`, client)
	SELECT 
		sod_preventive_check_violation.rule_id, 
		sod_preventive_check_violation.username, 
        sod_preventive_check_violation.system, 
        sod_preventive_check_violation.client
	FROM sod_preventive_check_violation
	WHERE sod_preventive_check_violation.handle IN(SELECT handle FROM sod_preventive_check_approval) AND 
		 sod_preventive_check_violation.rule_id IN(SELECT id FROM sod_rule) AND
		 sod_preventive_check_violation.warning_id = 2;