SELECT queryresult_string FROM xml_queryresult WHERE docid IN ( ( SELECT DISTINCT docid FROM xml_path_index WHERE (UPPER(nodedata) LIKE '%TEST%' AND path IN ('abstract/para','givenName','keyword','organizationName','title','surName','para','geographicDescription','literalLayout') ) ) ) AND ( docid IN ( SELECT docid from xml_access WHERE( (lower(principal_name) = 'public') AND perm_type = 'allow' AND permission > 3) ) AND docid NOT IN ( SELECT docid from xml_access WHERE( (lower(principal_name) = 'public') AND perm_type = 'deny' AND perm_order ='allowFirst' AND permission > 3) ) ) AND ( returnfield_id=1 ) AND( doctype IN ('eml://ecoinformatics.org/eml-2.0.1') ) Note: I added a new field - doctype in xml_queryresult table. If the table has this field, we don't need to join xml_documents table in our query to get document type info.