Databases: Cleaning the user table

Databases: Cleaning the user table

by Ângelo Rigo -
Number of replies: 0
Deleting students that have no courses

Hi

I have students that i need to clean from the user table being just the students that have no courses and came from the db method .

user
----
id
name

role
----
id
name

context
-------
id
instanceid (relates to course)

course
-------
id
fullname

role_assignments
----------------
roleid (relates to role: "student, teacher")
userid(relates to user)
contextid (relates to context)

This query brings the users who have any enrolment in a course

SELECT u.email from user u
inner join role_assignments ra on ra.userid=u.id
inner join role r on r.id=ra.roleid
inner join context ct on ra.contextid=ct.id
inner join course c on c.id=ct.instanceid
WHERE u.auth='db' AND r.id=5

how can io know wich users are not enrolled

Thank´s in advance
Average of ratings: -