-- This script deletes all users who do not have a role or cost centre
-- In other words, users who cannot use the application will be removed
-- from the users table.

DELETE users FROM
	users
	LEFT JOIN user_roles ur
		ON ur.service_number = users.service_number
	LEFT JOIN user_cost_centres cc
		ON cc.service_number = users.service_number
	WHERE
		ur.service_number IS NULL
		AND cc.service_number IS NULL;