SELECT outlet_type_id
FROM outlets   
WHERE outlet_type_id IS NOT NULL 
AND outlet_type_id NOT IN (SELECT id FROM outlettypes);

SELECT client_subtype_id 
FROM clients 
WHERE client_subtype_id IS NOT NULL 
AND client_subtype_id NOT IN (SELECT id FROM clientsubtypes);

UPDATE clients 
SET specialist_id = NULL 
WHERE specialist_id IS NOT NULL 
AND specialist_id NOT IN (SELECT id FROM specialists);

UPDATE clients 
SET client_subtype_id = NULL 
WHERE client_subtype_id IS NOT NULL 
AND client_subtype_id NOT IN (SELECT id FROM clientsubtypes);

DELETE FROM employees 
WHERE user_id IS NOT NULL 
AND user_id NOT IN (SELECT id FROM users);

UPDATE employees 
SET department_id = NULL 
WHERE department_id IS NOT NULL 
AND department_id NOT IN (SELECT id FROM departments);

UPDATE designations 
SET department_id = NULL 
WHERE department_id IS NOT NULL 
AND department_id NOT IN (SELECT id FROM departments);

UPDATE employees 
SET department_id = NULL 
WHERE department_id IS NOT NULL 
AND department_id NOT IN (SELECT id FROM departments);

UPDATE employees 
SET designation_id = NULL 
WHERE designation_id IS NOT NULL 
AND designation_id NOT IN (SELECT id FROM designations);

UPDATE employees 
SET user_id = NULL 
WHERE user_id IS NOT NULL 
AND user_id NOT IN (SELECT id FROM users);


UPDATE employees 
SET shifttype_id = NULL 
WHERE shifttype_id IS NOT NULL 
AND shifttype_id NOT IN (SELECT id FROM shifttypes);