DELETE FROM studies
WHERE NOT EXISTS (
    SELECT 1
    FROM users
    WHERE users.id = studies.user_id
);
DELETE FROM schedules
WHERE NOT EXISTS (
    SELECT 1
    FROM studies
    WHERE studies.id = schedules.study_id
);
DELETE FROM notifications
WHERE NOT EXISTS (
    SELECT 1
    FROM schedules
    WHERE schedules.id = notifications.schedule_id
);
