title: Pulling earliest date in specific criteria in google sheets
body: <p>Using google sheets, I'm trying to pull the earliest dates for unique values using the query function.</p>
  <p><a href="https://i.stack.imgur.com/hmlWH.png" rel="nofollow noreferrer">The Raw data looks like this</a></p>
  <p>I want to pull the data so that I only get the first test completed for each unique identifier provided that test was done within 2 days prior or after their ward admission. So it should spit out something like this:</p>
  <p><a href="https://i.stack.imgur.com/2KndE.png" rel="nofollow noreferrer">The data range I need</a></p>
  <p>I am using the following formula which is nearly what I want, it's just including multiple values for the unique identifers:</p>
  <pre><code>=Query(Sheet1!1:952,&quot;Select A,B,C,D,E where C &gt; -2 and C &lt; 2 and C is not null and E is not null Order By D&quot;,1)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/7gRPI.png" rel="nofollow noreferrer">Results I'm getting with the above formula</a></p>
  <p>I feel like I'm nearly there, I just need to somehow only pull the minimum date values instead of them all. Any help would be really appreciated!</p>