select id , '' as employee_id from table1
union
select id , emp_id as employee_id from table2
but i am getting error that incompatible datatype of employee_id from two joining union queries. so how to solve this issue.
emp_id is numeric datatype
If you want strings, then convert to strings:
select id , cast('' as varchar(255)) as employee_id from table1
union all
select id , cast(emp_id as varchar(255) as employee_id from table2;
Normally, you would use NULL
rather than ''
, which is more compatible with more types:
select id , NULL as employee_id from table1
union all
select id , emp_id as employee_id from table2;
Note that I changed the union
to union all
. union
incurs overhead for removing duplicates. Only use it if you want to incur that overhead.