一起运行2个SELECT语句,并将结果分成不同的列

时间:2015-10-08 09:23:22

标签: sql

我有这两个SELECT语句,我想一起查询它们,结果应该在不同的列中。我无法使用UNION,因为它只会产生一列。有什么简单的方法可以做到这一点吗?非常感谢你!

SELECT value from value_all where domainid='3851504'
SELECT value from value_all where domainid='3580420'

期望的输出:

value (1) | value (2)
---------------------
a         |    c
b         |    d

2 个答案:

答案 0 :(得分:0)

尝试使用别名:

    SELECT (SELECT value from value_all where domainid='3851504') AS 'value (1)' ,
           (SELECT value from value_all where domainid='3580420') AS 'value (2)'

答案 1 :(得分:0)

如果您使用CROSS JOIN或更高版本,请使用SQL Server 2005

SELECT A.Value [Value (1)], B.Value [Value (2)] FROM 
(SELECT value,
row_number() over (order by (select null)) r
 from value_all where domainid='3851504')A
CROSS JOIN
(SELECT value,
row_number() over (order by (select null)) r
 from value_all where domainid='3580420')B
 WHERE A.r = B.r