CREATE PROCEDURE scholarshipsDistribution() BEGIN SELECT candidate_id AS student_id FROM candidates WHERE candidate_id NOT IN (SELECT DISTINCT candidate_id AS id FROM candidates, detentions WHERE candidate_id = student_id ORDER BY candidate_id); END