sqljoinleft-joinunionqsqlquery

How to join two table without null data


I have two table named demoa and demob containing both same field ID and Name. For ex :

Demoa table containing data like

| Id | Name   |
| 1  | divya  |
| 2  | saumya |
| 3  | urvasi |

Demob table containing data like

| Id | Name  |
| 1  | karan |
| 2  | rekha |
| 3  | bhavna|
| 4  | bindu |

now when I merge both table its output coming like this with the latest query

| demoa | demob |
| divya |       |
| saumya|       | 
| urvasi|       |
|       | karan |
|       | rekha |
|       | bhavna|
|       | bindu |

here is the query

select a.name as demoa, '' as demob from demoa a
union all
select '', name from demob b

But I want output like this

| demoa | demob |
| divya | karan |
| saumya| rekha | 
| urvasi| bhavna|
|       | bindu |

I used join query also but didnt work for me


Solution

  •  SELECT A.ID,A.NAME,B.ID,B.NAME
     FROM DEMOA AS A
     FULL JOIN DEMOB AS B ON A.ID=B.ID