Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have example:
SQL
SELECT 1 AS ID, 'a' AS NAME1, null AS NAME2
UNION
SELECT 1 AS ID, 'a' AS NAME1, 'b' AS NAME2

Result:

ID NAME1 NAME2
1 a null
1 a b

How can it combined ?

ID NAME1 NAME2
1 a b
Posted
Updated 14-Nov-12 5:22am
v2

1 solution

you can't. You did a union asking for the null value, so you have it. I don't know what you mean by 'combined', but you are selecting the same thing as NAME1 in both cases, so there's nothing to combine. You're getting exactly what you asked for, and based on your question, there's nothing else you could want, apart from removing the union
 
Share this answer
 
Comments
RaisKazi 14-Nov-12 11:25am    
My 5. Exactly, question makes no sense. OP ordered Coffee-Mocha and shouting why I am getting Chi-Latte. :)))
Christian Graus 14-Nov-12 11:26am    
More correctly, he ordered a mocha, and shouted 'there's chocolate in my coffee !!' :P
RaisKazi 14-Nov-12 11:28am    
:))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900