3

これはクエリですが、結果から上位1つを選択するにはどうすればよいですか?これはSQLServer用です。

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

UNION

SELECT column4 
FROM table 
WHERE column2 = 'Whatever' AND column3 = 'Sure'
4

3 に答える 3

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
于 2012-04-15T20:38:22.437 に答える
2

試す:

SELECT max(Column) FROM (
  SELECT column1 as Column FROM table WHERE ....
  UNION 
  SELECT column4 as Column FROM table WHERE ....
)
于 2012-04-15T20:35:56.433 に答える
1

意味ですか

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')
于 2012-04-15T20:36:18.690 に答える