Get MIN value for each id

Im trying to get the min time for each call. Each call can have sevealr parts to it all logged on the same call id. What I want to do is fine the min time for each call id but im getting duplicate values when I query it one way or if I query it another way I just get the min value.

I want to end up with being able to count all the calls by hour

this is the query I have been playing with to try and get the unique call id and time but this returns duplicates currently


Callid 1 = 2014-07-04 16:37:22.043

callid 2 = 2014-07-04 16:37:23.370

what I want is just the values from called 1

select t.callid, (select min(timein) from loggeddata t2 where t2.callid = t.callid and t2.timein > t.timein
                    ) as 'mintime'
      from loggeddata t


You don't need a subquery for that, just use GROUP BY to define the grouping expression and add the aggregation as a column:

select t.callid, 
       min(timein) as 'mintime' 
from loggeddata 
GROUP BY callid