title: how to get around problems with group by, aggregate
body: <p>I have the following query:</p>
  
  <pre><code>SELECT d.currentDate, t.ConfigId, t.value as value
  FROM    #Dates AS d
          OUTER APPLY
          (   SELECT  t.value as value, t.FK_ShipDataSubsystemConfigId
              FROM    myTable AS t
              WHERE   t.[Timestamp] &lt;= d.currentDate and t.ConfigId in (' + @IDList + ')
              and t.FK_DataSystemId &lt;&gt; 1
          ) AS t 
  GROUP BY d.currentDate, t.ConfigId
  )
  </code></pre>
  
  <p>where <code>Dates</code> is just a table holding a bunch of datetimes I am using to ensure I get the data at the intervals I need. </p>
  
  <p>My problem is with the <code>group by</code> clause. The query doesn't work as is because <code>value</code> is not in the <code>group by</code> or an aggregate function. I tried grouping by <code>value</code> also to make the error go away, but it just gives me every single date in the interval I am selecting on matched to every single value -- not what I want. I should end up with a table with one row for each date/ConfigId pairing. </p>
  
  <p>When I remove value from the <code>select</code> and just get the date and the <code>ConfigId</code>, it works fine. I get the exact number of rows I should be getting. </p>
  
  <p>The table I'm pulling from looks like this:</p>
  
  <pre><code>PK_DataId    Timestamp        value     ConfigId
  1            1/1/2015 12:00   234       5
  2            1/1/2015 12:01   456       4
  </code></pre>
  
  <p>I am expecting to get back this:</p>
  
  <pre><code>Timestamp            value        ConfigId
  1/1/2015 12:00:00    234          5
  1/1/2015 12:00:00    456          4
  </code></pre>
  
  <p>Where I have a value for each configId/date pair from every fifteen minutes. When I add max(value) I only get one value for every time instead of different ones. When I group by value I get millions of rows, it looks like I am getting one row for each timestamp matched with each value from any other timestamp. I don't really understand what is happening. </p>
  
  <p>How can I get those results while also selecting <code>value</code>? </p>