Last active
October 20, 2016 14:32
-
-
Save henderjon/a4653d18f101fa9378ccf0d147c963fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP PROCEDURE IF EXISTS deleteBadProjectAssignments; | |
DELIMITER $$ | |
CREATE PROCEDURE deleteBadProjectAssignments( ) | |
BEGIN | |
DROP TEMPORARY TABLE IF EXISTS table2; | |
CREATE TEMPORARY TABLE IF NOT EXISTS table2 AS( | |
SELECT DISTINCT | |
utp.project_id | |
FROM | |
users_to_projects utp | |
INNER JOIN users u ON utp.user_id = u.user_id | |
INNER JOIN projects p ON utp.project_id = p.project_id | |
WHERE | |
utp.project_id NOT IN( | |
SELECT | |
utp2.project_id | |
FROM | |
users_to_projects utp2 | |
INNER JOIN users u ON utp2.user_id = u.user_id | |
WHERE | |
u.user_role_id != 2 | |
) | |
AND p.system != 1 | |
GROUP BY | |
project_id , | |
u.user_role_id | |
ORDER BY | |
utp.project_id | |
); | |
delete from users_to_projects where project_id in ( | |
select project_id from table2 | |
); | |
END $$ | |
DELIMITER ; | |
CALL deleteBadProjectAssignments(); | |
DROP PROCEDURE IF EXISTS deleteBadProjectAssignments; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 but I'd test it on a test db first