title: Queries on Joins in Cosmos DB Sql API
body: <p>This document has an example query to run against a Cosmos DB SQL API</p>
  
  <p><a href="https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-query-sql-api#example-query-2" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-query-sql-api#example-query-2</a></p>
  
  <pre><code>SELECT c.givenName 
  FROM Families f 
  JOIN c IN f.children 
  WHERE f.id = 'WakefieldFamily'
  ORDER BY f.children.grade ASC
  </code></pre>
  
  <p>Using <a href="https://www.documentdb.com/sql/demo" rel="nofollow noreferrer">https://www.documentdb.com/sql/demo</a></p>
  
  <p>I couldn't get a similar example to work until I put a [0] into the order by. I just got {}. NB I know the URL says documentdb but the page header on that page says Cosmos DB</p>
  
  <pre><code>SELECT food.servings[0].amount
  FROM ROOT food
  WHERE food.id = "19015"
  order by food.servings[0].amount
  </code></pre>
  
  <p>Should it work?</p>
  
  <p>Is there a document somewhere that covers all the queries you can run against this API?</p>
  
  <p>(extra info)</p>
  
  <p>(1) Go to <a href="https://www.documentdb.com/sql/demo" rel="nofollow noreferrer">https://www.documentdb.com/sql/demo</a></p>
  
  <p>(2) Put this query in against it</p>
  
  <pre><code>SELECT food.servings[0].amount
  FROM ROOT food
  WHERE food.id = "19015"
  order by food.servings[0].amount
  </code></pre>
  
  <p>It works, but this query looks nothing like the example in <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-query-sql-api#example-query-2" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-query-sql-api#example-query-2</a>, it uses a '[0]' which isn't needed in the original example.</p>