title: SQL Server query : SELECT 1 WHERE EXISTS versus SELECT TOP 1 1
body: <p>I need to present a flag - 0 if a condition is not meet, 1 if it is - and I can do it in two different ways :</p>
  
  <p>Get Employee ID, name, 1 if has others in suborder - 0 if not :  </p>
  
  <pre><code>SELECT e.ID
       , e.Name
       , ISNULL ( ( SELECT TOP 1 1 FROM Employee se WHERE se.ManagerID = e.ID ) , 0 ) AS HasSubordinates 
    FROM Employee e
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SELECT e.ID
       , e.Name
       , ISNULL ( ( SELECT 1 WHERE EXISTS ( SELECT * FROM Employee se WHERE se.ManagerID = e.ID ) ) , 0 ) AS HasSubordinates 
    FROM Employee e
  </code></pre>
  
  <p><strong>Which version would you choose and why ?</strong></p>
  
  <h2><br></h2>
  
  <h1>Update 1</h1>
  
  <p><br></p>
  
  <p>How about this one ?</p>
  
  <pre><code>SELECT o.ID
       , o.Name
       , o.StartDate
       , o.EndDate
       , ISNULL ( ( SELECT TOP 1 1 FROM changes c WHERE c.ChangeDate BETWEEN o.StartDate AND o.EndDate ) , 0 ) AS IsChanged
    FROM Orders o
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SELECT o.ID
       , o.Name
       , o.StartDate
       , o.EndDate
       , ISNULL ( ( SELECT 1 WHERE EXISTS ( SELECT * FROM changes c WHERE c.ChangeDate BETWEEN o.StartDate AND o.EndDate ) ), 0 ) AS IsChanged
    FROM Orders o
  </code></pre>