Reputation: 527
Is it possible to make a query containing 4 SELECT statements where each result is placed in its own column? How?
I'm currently sitting with 4 queries that I need to somehow combine into 1 and I've tried using UNION but it seems to put the results in the same column, just a new row.
Thanks.
Upvotes: 0
Views: 88
Reputation: 460028
You can use sub-queries and a column alias:
SELECT (SELECT TOP 1 Col1 From dbo.Table2 WHERE Condition1)AS Col1
, (SELECT TOP 1 Col1 From dbo.Table3 WHERE Condition2)AS Col2
FROM dbo.Table1
Using a Subquery in a T-SQL Statement
Upvotes: 1
Reputation: 107686
If the SELECT statements each return a SCALAR result, i.e. single-row, single-column - then yo can just do this:
SELECT (select .... ) Column1,
(select .... ) Column2,
(select .... ) Column3,
(select .... ) Column4;
Upvotes: 2