correlated sub query to select ids of earliest entry
<p>I am currently using this:</p>

<pre><code>IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp

CREATE TABLE #Temp
(
    SomeId INT,
    UtcDateTime DATETIME2
)

INSERT INTO #Temp
    SELECT 1, DATETIME2FROMPARTS(2015,1,1,1,1,1,0,0)
        UNION 
    SELECT 1, DATETIME2FROMPARTS(2015,1,1,2,1,1,0,0)
        UNION 
    SELECT 2, DATETIME2FROMPARTS(2015,1,1,3,1,1,0,0)
        UNION 
    SELECT 2, DATETIME2FROMPARTS(2015,1,12,4,1,1,0,0)
        UNION 
    SELECT 2, DATETIME2FROMPARTS(2015,1,12,5,1,1,0,0)
        UNION 
    SELECT 3, DATETIME2FROMPARTS(2015,1,12,5,1,1,0,0)

SELECT * FROM #Temp ORDER BY UtcDateTime ASC

SELECT 
    *
FROM #Temp AS O1
WHERE UtcDateTime =
(
    SELECT MIN(UtcDateTime) FROM #Temp AS O2 WHERE O1.SomeId = O2.SomeId 
)
AND SomeId =
(
    SELECT MAX(SomeId) FROM #Temp AS O2 WHERE O1.SomeId = O2.SomeId AND O1.UtcDateTime = O2.UtcDateTime
)
</code></pre>

<p>The intention is to select the first occurrence for each entry with a distinct SomeId based on UtcDateTime. In other words, I am after these rows:</p>

<pre><code>SomeId  UtcDateTime
1   2015-01-01 01:01:01.0000000
2   2015-01-01 03:01:01.0000000
3   2015-01-12 05:01:01.0000000
</code></pre>

<p>Is the above correlated sub query approach correct? </p>