title: How do I get unique values from nested Many-To-Many joins
body: <p>Basically we have four tables that are joined: Malls, Stores, Brands, and Categories.</p>
  
  <p>Malls can have many Stores.
  Each Store is linked to a Brand.
  Each Brand has many Categories.</p>
  
  <p>e.g. Mall A has 2 "McDonald's Cafes", each belonging to the Brand "McDonald's". "McDonald's" Brand has "Fast Food" and "Breakfast" as Categories.</p>
  
  <p>We're trying to figure out how to display all the Categories that exist within Mall A.</p>
  
  <p>e.g. Mall A has "Fast Food" and "Breakfast" categories, based on the "McDonald's" stores.</p>
  
  <p>Ideally this would be a query so that the Categories are updated automatically.</p>
  
  <p>We've tried querying for all Stores within a Mall, and then finding the Categories via the Store-Brand join, then reducing duplicates. But some Malls have more than 700 Stores, so this process is quite expensive in terms of querying and processing the data.</p>