Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I combine sql tables like this?

Table1:
|first  |last         |hair    |
|peter  |Jackson      |brown   |


Table2:
|pet |hair     |
|dog |grey     |
|cat |         |



Output table:
|first    |last         |hair    |pet  |
|peter    |Jackson      |brown|        |
|         |             |grey    |dog  |
|         |             |        |cat  |


It doesn't have to actually create the third table just create a temporary selectable one.
[edit]Code block added - OriginalGriff[/edit]

What I have tried:

I haven't tried anything yet.
I know there are some sql joining commands, but I don't want to go this way if it isn't the right one.
Posted
Updated 21-Aug-16 5:28am
v3
Comments
Maciej Los 21-Aug-16 13:58pm    
Is there any relationship between tables?

1 solution

Try a UNION:
SQL
SELECT first, last, hair, null AS pet FROM Table1 UNION ALL SELECT null, null, hair, pet FROM Table2
 
Share this answer
 

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