How do I get the TOP 1 value from a UNION of 2 columns?

sql-server

Solution

Try this:

SELECT TOP 1 * FROM
(
  SELECT column1 FROM table WHERE column2 = 'Whatever' AND column3 = 'Sure'
  UNION
  SELECT column4 FROM table WHERE column2 = 'Whatever' AND column3 = 'Sure'
) R
ORDER BY Column1

Problem

This is the query, how do I select the top 1 from the result? This is for SQL Server. ``` SELECT column1 FROM table WHERE column2 = 'Whatever' AND column3 = 'Sure' UNION SELECT column4 FROM table WHERE column2 = 'Whatever' AND column3 = 'Sure' ```

Original source