Sql server 如何从两列的并集中获取前1个值?

Sql server 如何从两列的并集中获取前1个值?,sql-server,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' 尝试: 你是说 SELECT TOP 1 * FROM ( SELECT column1 FROM t

这是查询,如何从结果中选择前1名?这是针对SQL Server的

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

UNION

SELECT column4 
FROM table 
WHERE column2 = 'Whatever' AND column3 = 'Sure'
尝试:

你是说

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')
试试这个:

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
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