title: select employee on name and dep if not exists select top 1 employee for dept
body: <p>I have requirement to fetch record from <code>employee</code> table with conditions on <code>name</code> and <code>department</code>. If no record exists for that name and depart, then it should return top 1 record from the <code>employee</code> for that <code>department</code>.</p>
  
  <p>Ex: </p>
  
  <pre><code>SELECT * FROM EMPLOYEE WHERE NAME = 'SQL' AND DEPID = 1
   IF NOT EXISTS 
       SELECT TOP 1 * FROM EMPLOYEE WHERE DEPID = 1
  </code></pre>
  
  <p>Can this be achived with in a single query and also considering the performance.</p>