我有四个选择查询四个不同的表,每个提取只有一个记录。例如:结合许多选择查询的结果集
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