select d.cdr_recordId, d.cdr_dstName from tbl_CDR_Distributors d where d.ownerId = and d.fsl_tablecode = and d.cdr_dstCompanyType = 'B' and exists ( select * from tbl_CDR_invoiceHistory ih where ih.cdr_RecordId = d.cdr_recordId and ih.ownerId = d.ownerId and ih.ownerType = d.fsl_tablecode ) and d.fsl_dstId > 0 order by cdr_dstName