CREATE TEMPORARY TABLE orphaned_configs AS (select config_id,type_name,version_tag from clusterconfig where unmapped != 1 and type_name not in ('cluster-env') and config_id not in ( SELECT cc.config_id FROM clusterconfig cc, serviceconfig sc, serviceconfigmapping scm WHERE cc.type_name != 'cluster-env' AND cc.config_id = scm.config_id AND scm.service_config_id = sc.service_config_id)); Update clusterconfig set unmapped = 1 where config_id in (select config_id from orphaned_configs); drop table orphaned_configs;