我有四個選擇查詢四個不同的表,每個提取只有一個記錄。例如:結合許多選擇查詢的結果集
Select * from table where col1 = 'something'
給出一行有3列。
第二個選擇查詢還給出了一個具有兩列(字段)的記錄。第三和第四個選擇查詢也一樣。
我想將所有四個結果集合成一個有一行的結果集。這怎麼可能?
我會爲你寫查詢。
第一之一:
Select Top 1 column1, column2
from table 1
where column 1 = 'something'
and col1 = (Select max(col1) where column 1 = 'something')
第二查詢:
Select Top 1 column1, column3
from table 2
where column 1 = 'something'
and column3 = (Select max(column3) where column 1 = 'something')
第三查詢使用從查詢2獲得的結果是:
Select column4
from table 3
where column3 = (obtained from 2nd query) (there is only one row)
第四:
Select column5
from table 4
where column3 = (obtained from 2nd query) (there is only one row)
這意味着我必須加入第2,3,4個查詢,然後在第1個查詢結果集。
由於列不同,我無法使用聯合。
所以唯一的問題是加入結果集。
在任何表 – AChamp 2012-08-09 11:07:48
之間沒有共同的字段發佈查詢將是非常有用的。 – Taryn 2012-08-09 11:07:56
你爲什麼要這樣做?聽起來像是一個壞計劃... – Thomas 2012-08-09 11:18:08