Find if a parameter exists across any contacts for a given account

Find if a parameter exists across any contacts for a given account

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!!

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation
                                              • Sticky Posts

                                              • Announcing Zoho Analytics 6.0 Beta!

                                                We are delighted to open up the next major version, Zoho Analytics 6.0 Beta! The new version comes packed with a wide range of functionalities for all persona, namely business users, data analysts, data engineers, and data scientists. Zoho Analytics team
                                              • What's New in Zoho Analytics - August 2024

                                                Hello Users! We are back with the latest updates and enhancements made to Zoho Analytics. Keep reading to learn more about them. Connect to the data hosted in the cloud without allow-listing the IP addresses Utilize Zoho Databridge to connect to the data
                                              • We are coming to your city! Zoho Analytics Community Meetup

                                                Hello, business leaders and data enthusiasts! We are delighted to announce that registrations are now open for the ZUG meetups, and we can't wait for you to be a part of them. Our in-house analytics experts are geared up to lead discussions on constructing
                                              • Zoho Analytics: 2021 Look Back

                                                As we start a new year in 2022, here's some of our top moments from 2021. Zoho Analytics in 2021
                                              • [Customer Talk] PREMO Group's Analyst Interview at Zoho Day 2022

                                                Premo Group, a 50 year old Spanish Manufacturing Company, has been our long-standing customer with #ZohoAnalytics. They've been using our platform for their end-to-end, unified business analytics solution.  Hear more from Claudio Cabeza, Director at PREMO


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now