title: How do I make a inner join as a condition in GROQ?
body: <p>I have a dataset with <em>posts</em>, which might have an array of categories.</p>
  
  <p><strong>How do I make a GROQ query that selects all posts with a category with the title <em>"Page"</em>?</strong></p>
  
  <p>I would think that I could do something like this:</p>
  
  <pre><code>*[_type == 'post' &amp;&amp; categories[]-&gt;title == 'Page']{
    body,
    slug,
  }
  </code></pre>
  
  <p>I probably need to use function for matching inside an array but <a href="https://www.sanity.io/docs/data-store/query-cheat-sheet" rel="noreferrer">the cheetsheet</a> is too dense for me - I just can't find it.</p>
  
  <p>The gist of my dataset is:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    {
      _createdAt: "2018-08-24T17:59:04Z",
      _id: "e84d78f0-81ed-4524-9c36-f38a1f1b2375",
      _rev: "1X9D03Y03BUslZ33alDJwF",
      _type: "category",
      _updatedAt: "2018-08-24T18:13:14Z",
      description: "Pages/Sider",
      title: "Page"
    },
    {
      _createdAt: "2018-08-26T21:57:54Z",
      _id: "3c023e29-b167-4021-be00-5e8dc14f65cc",
      _rev: "WQjjTjyYBRudo6JCOBCUj7",
      _type: "post",
      body: [
        {}
      ],
      categories: [],
    },
    {
      _createdAt: "2018-08-24T17:57:55Z",
      _id: "3d8f0c40-a45d-4dc7-ad95-ed1b49bca4af",
      _rev: "WQjjTjyYBRudo6JCO0spXR",
      _type: "post",
      body: [
        {}
      ],
      categories: [
        {
          _key: "491c03573205",
          _ref: "e84d78f0-81ed-4524-9c36-f38a1f1b2375",
          _type: "reference"
        }
      ]
    }
  }
  </code></pre>
  
  <p>A simple query:</p>
  
  <pre><code>*[_type == 'post']{
    //  body,
    "category": categories[]-&gt;title,
    //  slug,
    categories
  }
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>{
    categories: [],
    category: []
  }
  
  {
    categories: [
      {
        _key: "491c03573205",
        _ref: "e84d78f0-81ed-4524-9c36-f38a1f1b2375",
        _type: "reference"
      }
    ],
    category: [
      Page
    ]
  }
  </code></pre>