UserSN
UserSN

Reputation: 1013

TSQL Concatenating data from 2 tables

How can I concatenate the data from both of these tables so as they appear to be in just 1 single table.

Table 1:
JobID,Company,Category,url,reference,description,etc...

Table 2:
JobID,EmployerID,CompanyName,Category,Status,Description,etc...

There are additional fields in both of these tables but basically there are matching information such as company, category, description, etc.. that should match up correctly & I would like to display the matching columns from both tables in 1 SELECT statement.

Example Desired results: (Mixed results from both tables)

 (Source)   JobID    CompanyName       Category      Description
 tbl1       1        ABC Liquor        Sales Clerk   Looking for someone...
 tbl2       2        Tiffanys Salon    Beauty        Looking for someone...    
 tbl2       3        Barber Shop       Beauty        Looking for someone...
 tbl1       4        Car Wash          Services      Looking for someone...

Upvotes: 0

Views: 45

Answers (1)

Abdul Rasheed
Abdul Rasheed

Reputation: 6719

Use UNION

select company, category, description from First_Table
UNION
select CompanyName, category, Description from Second_Table

Following conditions should be satisfied,

  1. Each SELECT statement within UNION must have the same number of columns
  2. The columns must also have similar data types
  3. The columns in each SELECT statement must also be in the same order

Upvotes: 1

Related Questions