title: SQL Server Top 1
body: <p>In Microsoft SQL Server 2005 or above, I would like to get the first row, and if there is no matching row, then return a row with default values.</p>
  
  <pre><code>SELECT TOP 1 ID,Name
  FROM TableName
  UNION ALL 
  SELECT 0,''
  ORDER BY ID DESC
  </code></pre>
  
  <p>This works, except that it returns two rows if there is data in the table, and 1 row if not.
  I'd like it to always return 1 row.
  I think it has something to do with EXISTS, but I'm not sure.
  It would be something like:</p>
  
  <pre><code>SELECT TOP 1 * FROM Contact 
  WHERE EXISTS(select * from contact)
  </code></pre>
  
  <p>But if not EXISTS, then SELECT 0,''</p>