@ian.mcnicoll The OR in the WHERE for the template_id doesn’t assure the EHR contains COMPOS for both template_ids. I understood in the original query that was the requirement: retrieve EHRs which contains COMPOSITIONs for both template_ids (AT THE SAME TIME, not one or the other, both instances should exist) and have certain code at some coded text.
Correct me if I’m wrong @Sravanthi_Kovi