title: T-SQL SELECT TOP 1
body: <p>I'm running a query where I want to select the first row from a query result. If I have two rows in the table it will return a result but if I only have one it won't return anything.</p>
  
  <pre><code>select TOP 1 u.ID
  from [dbo].[User] u
  where u.ID &lt;&gt; '5dc89076-e554-42f2-a9ae-787b20f6f56b' AND u.gender != 'male'
  except
  select [dbo].[Like].likes
  from [dbo].[Like]
  where [dbo].[Like].[user] = '5dc89076-e554-42f2-a9ae-787b20f6f56b'
  except
  select [dbo].[Dislike].dislikes
  from [dbo].[Dislike]
  where [dbo].[Dislike].[user] = '5dc89076-e554-42f2-a9ae-787b20f6f56b'
  </code></pre>
  
  <p>This query returns nothing</p>
  
  <pre><code>select u.ID
  from [dbo].[User] u
  where u.ID &lt;&gt; '5dc89076-e554-42f2-a9ae-787b20f6f56b' AND u.gender != 'male'
  except
  select [dbo].[Like].likes
  from [dbo].[Like]
  where [dbo].[Like].[user] = '5dc89076-e554-42f2-a9ae-787b20f6f56b'
  except
  select [dbo].[Dislike].dislikes
  from [dbo].[Dislike]
  where [dbo].[Dislike].[user] = '5dc89076-e554-42f2-a9ae-787b20f6f56b'
  </code></pre>
  
  <p>This query returns Id:9EF5B83E-319A-4E2F-88A1-E67227DBFDCE</p>