简体   繁体   中英

Temporary table with two tables data with no column in common should return data in one column

I have following temporary table

Create table #Test
(
colA int,
colB int,
colC int,
colD int,
colE int
)

I insert the data in it as follows:

INSERT INTO #Test(colA, colB, colC)
Select A, B C
FROM Table a innerjoin Table b
WHERE (some logic)

INSERT INTO #Test (colD, colE)
Select D, E
FROM Table C innerjoin Table D
WHERE (some logic)

Select * from #Test
drop table #Test

I will get output as :

colA colB colC colD colE
val1 val2 val3 null null
null null null val4 val5

But I need output as follows :

colA colB colC colD colE
val1 val2 val3 val4 val5

Please help me to achieve it.

try below query

Select max(col1), max(col2), max(col3).... from #Test
group by col1,col2,col3....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM