Reputation: 26498
I have the below
;with cte as(
Select 1 as Col1 ,NULL as Col2
Union All
Select Null ,2)
select *
from cte
/* Result*/
Col1 Col2
1 NULL
NULL 2
I am looking for
Col1 Col2
1 2
i.e. results should come in a single row.
How can we achieve this?
Upvotes: 0
Views: 65
Reputation: 136
Using cartesian join we can get the required result:
select t2.a,t1.b from table t1,table t2 where t1.b is not null and t2.a is not null;
Upvotes: 0
Reputation: 39
1With the limited information in your question is this what your trying achieve?
;with cte as(
Select table1.Col1 , table2.Col2 From Table1
JOIN table2
ON table1.col1 = table2.Col1
WHERE table1.Col1 = 1 and table2.Col2 = 2
)
select *
from cte
Upvotes: 1
Reputation: 1145
You can use any aggregate function like Max() or Min() or Sum() depends on your requirement .
Upvotes: 1
Reputation: 36473
Without more details about your data, it seems like applying a simple aggregate function like max
should do what you are after:
...
select max(col1) as col1, max(col2) as col2
from cte
Upvotes: 2