select b.broker_id as pkId, b.broker_name as name from tblBrokers b where exists ( select * from tbl_LIB_Companies where companyPKeyId = b.broker_id and companyPType = 'BRO' ) and exists ( select * from tbl_OPR_ClientSegments where ownerId = b.broker_id and fsl_tablecode = 'BRO' ) order by b.broker_name select m.mfr_id as pkId, m.mfr_name as name from tblManufacturers m where exists ( select * from tbl_LIB_Companies where companyPKeyId = m.mfr_id and companyPType = 'MFR' ) and exists ( select * from tbl_OPR_ClientSegments where ownerId = m.mfr_id and fsl_tablecode = 'MFR' ) order by m.mfr_name select c.cho_id as pkid, c.cho_name as name from tbl_CHO_Operators c where exists ( select * from tbl_LIB_Companies where companyPKeyId = c.cho_id and companyPType = 'CHO' ) order by c.cho_name
Geo Dupes
select opr.operatorId, opr.CompanyName, opr.Address, opr.City, opr.State, opr.ZipCode, opr.mdmId, geo.latitude, geo.longitude, ter.name, opr.lastInteractionDate, opr.dateCreated, opr.recordSource, ( select count(*) from tbl_GEO_locations geo2 inner join tbl_OPR_ClientOperators opr2 on geo2.ownerId = opr2.OwnerID and geo2.ownerType = opr2.FSLTableCode and geo2.partnerId = opr2.OperatorID where geo2.ownerId = and geo2.ownerType = and geo2.latitude = geo.latitude and geo2.longitude = geo.longitude and opr2.CRMActive = 'Y' ) possibleDupes from tbl_OPR_ClientOperators opr inner join tbl_GEO_locations geo on opr.OwnerID = geo.ownerId and opr.FSLTableCode = geo.ownerType and opr.OperatorID = geo.partnerId left outer join tbl_TER_Territories ter on ter.ownerId = opr.ownerId and ter.fsl_tablecode = opr.fsltablecode and ter.territoryId = opr.territoryId where opr.OwnerID = and opr.FSLTableCode = and opr.CRMActive = 'Y' and ( geo.latitude <> 0 and geo.longitude <> 0 ) order by opr.CompanyName select * from qmd_geolocations where possibleDupes > 1 order by latitude, longitude