Hi, I finally got this to work. I am actually testing in access so I had to change the case statement to a iif statement.Could someone take a look and let me know if this is the best way to do this? I added in my additional fields and query names once I knew I had something that worked.SELECT q1.PBM, q1.Parentname, q1.Providername, q1.planname, q1.plantype, q1.formularystatus & IIf(q2.countofplanname>1," - plan by plan may differ","") AS Formulary, q1.drugnameFROM tblMarketMatching INNER JOIN ((qrymaxcounts AS q1 INNER JOIN qrycounts AS q2 ON (q1.drugname = q2.DrugName) AND (q1.planname = q2.planname)) INNER JOIN (SELECT planname, MAX(sumoflives) AS MaxLives, drugname FROM qrymaxcounts GROUP BY planname, drugname) AS q21 ON (q1.drugname = q21.drugname) AND (q1.planname = q21.planname) AND (q1.sumoflives = q21.MaxLives)) ON tblMarketMatching.Product = q1.drugnameGROUP BY q1.PBM, q1.Parentname, q1.Providername, q1.planname, q1.plantype, q1.drugname, [q1].[formularystatus] & IIf([q2].[countofplanname]>1," - plan by plan may differ","");
What each query returns -qryMaxCounts - sum of lives grouped by multiple attributes.qryCounts - count of combinations of drug and plan. If greater than 1 tells me that there are differences amongst plans.tblMarketMatching - limits which product group to return.Goal of query is to return the status of the plan with the greats live count. Then check the plan against the plan account. If > 1 place concatenate text to status.