Syed Imran Shah
Syed Imran Shah

Reputation: 43

Merging two tables in query

I have two tables in SQL Server 2008 R2. One is called customer and data in the table is like this:

enter image description here

The second table is called Operators and data looks like this:

enter image description here

The result should combine data from both tables and look like this:

enter image description here

Upvotes: 0

Views: 46

Answers (2)

Ajeet Verma
Ajeet Verma

Reputation: 1123

Please try this as well ..

SELECT BrID
       ,Customer_Id
       ,0 as Account_Id
       ,Customer_Name as [Customer name]
       ,NIC_No
FROM Customer

UNION ALL

select BrID
       ,Customer_Id
       ,Account_Id
       ,CONCAT(First_Name,' ',Last_Name) as [Customer name]
       ,NIC_No
FROM Operator

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269483

I think you want union all:

select brid, customer_id, 0 as account_id, customer_name, nic_no
from customers
union all
select brid, customer_id, account_id, (first_name + ' ' + last_name) as customer_name, nic_no
from operators;

Upvotes: 1

Related Questions