如何从2列UNION中获取TOP 1值?

Alt*_*tex 3 sql-server

这是查询,如何从结果中选择前1?这适用于SQL Server.

SELECT column1 
FROM table 
WHERE column2 = 'Whatever' AND column3 = 'Sure'

UNION

SELECT column4 
FROM table 
WHERE column2 = 'Whatever' AND column3 = 'Sure'
Run Code Online (Sandbox Code Playgroud)

Ken*_*ite 7

试试这个:

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
Run Code Online (Sandbox Code Playgroud)