これはクエリですが、結果から上位1つを選択するにはどうすればよいですか?これはSQLServer用です。
SELECT column1
FROM table
WHERE column2 = 'Whatever' AND column3 = 'Sure'
UNION
SELECT column4
FROM table
WHERE column2 = 'Whatever' AND column3 = 'Sure'
これはクエリですが、結果から上位1つを選択するにはどうすればよいですか?これはSQLServer用です。
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 max(Column) FROM (
SELECT column1 as Column FROM table WHERE ....
UNION
SELECT column4 as Column FROM table WHERE ....
)
意味ですか
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')