Hi - I am trying to write a query that will find any account that purchases a certain Brand from our company but does not have
any contacts identified as Buying for that Brand.
Brands are listed in a custom multi-select "Brands" field in the Accounts Module. These brands have been split out in a query table "***NEW*** Account Brands Table" so that each Account-Brand combination has its own row.
The same brand options are also available for selection in the Contacts Module under the custom multi-select "Buys for..." field. The idea is for each Brand an Account buys there should be at least one Buyer who Buys for the Brand in Contacts.
I'm trying to find where we have gaps (i.e., Brands that don't have a Buyer identified).
I wrote the following query that works for each Contact individually. But I really want to know is whether the Brand has a Buyer across multiple contacts. So one buyer could buy for Brand A and another could buy for Brand B but across both contacts all the Brands are covered.
Does anyone know how to edit my query so that it will look across multiple rows?
SELECT DISTINCT
AB."Account ID",
A."Account Owner",
AB."Account Name",
AB."Brand"
FROM "***NEW*** ACCOUNT BRANDS TABLE" AB
JOIN "Contacts" C ON AB."Account ID" = C."Account ID"
JOIN "Accounts" A ON C."Account ID" = A."AccountID"
WHERE
indexof(C."Buys for...", AB."Brand") < 1
AND
A."Parent Account ID" IS NULL
Thanks in advance for your help!!