SELECT DISTINCT tt.term_id FROM wp_posts p

        INNER JOIN wp_term_relationships tr_target ON tr_target.object_id = p.ID

        INNER JOIN wp_term_taxonomy tt
            ON tt.term_taxonomy_id = tr_target.term_taxonomy_id AND tt.taxonomy = 'category'

        INNER JOIN wp_term_relationships tr_domain ON tr_domain.object_id = p.ID

        INNER JOIN wp_term_taxonomy tt_domain ON tt_domain.term_taxonomy_id = tr_domain.term_taxonomy_id

        INNER JOIN wp_terms t_domain ON t_domain.term_id = tt_domain.term_id

        WHERE
            p.post_status='publish' 
            AND p.post_type IN ('post','forum','topic','reply')
            AND tt_domain.taxonomy='source_domain'
            AND t_domain.slug='insidetechie.blog'
    
            AND NOT EXISTS (
                SELECT 1 FROM wp_term_relationships trs
                INNER JOIN wp_term_taxonomy tts ON tts.term_taxonomy_id = trs.term_taxonomy_id
                WHERE trs.object_id = p.ID AND tts.taxonomy='source_subdomain'
            )