title: IN clause in select query with a subquery
body: <p>I have a query where I join multiple tables. I would like to filter the results based on the status codes and I also want to get the records that were most recently created. Is the below SQL correct? Meaning - can I use IN clause for the statuscodes, or should it be three different queries, one for each status?</p>
  
  <pre><code>SELECT
           A.DetailID
         , H.PersonID
         , A.RateAmount
         , A.Code
         , A.TypeCode
  FROM
           CMPN.Detail       A
         , CMPN.DetailStatus B
         , CMPN.Header       H
  WHERE
           H.PayGroup IN ('A Pay Group','B Pay Group','C Pay Group')
           AND A.EndDate = '2020-02-10 06:00:00.0000000 +00:00'
           AND A.LastUpdateTimestamp      &lt;= '2020-02-24 06:00:00.0000000 +00:00'
           AND A.DetailID = B.DetailID
           AND H.HeaderId = A.HeaderId
           AND **B.DetailStatusCode IN ('Approved','Completed','Pending')**
           AND B.CreateTimestamp =
           (
                  SELECT
                         MAX(C.CreateTimestamp)
                  FROM
                         CMPN.DetailStatus C
                  WHERE
                         A.DetailID = C.DetailID AND **C.DetailStatusCode IN ('Approved','Completed','Pending'**)
           )
  ORDER BY
           H.PersonID
         , A.Code
         , A.TypeCode
  </code></pre>