Avatar of tmajor99
tmajor99
 asked on

SQL - Appending data from another table with different column names

how can i append data from another table with different column names..  

Table 1:                                        Table 2:

Group         ID                              SectionGroup            PartID
--------      --------                     ----------------         -----------
100             A                                300                            C
200             B

Expected Result:

Group         ID
-------       -----
100             A
200             B
300             C
Microsoft SQL Server

Avatar of undefined
Last Comment
Scott Pletcher

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Nakul Vachhrajani

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Scott Pletcher

Just fyi, you don't need the column names on the second(+) query in a UNION, SQL uses the names from the first query.  This is fine:


SELECT [GROUP] AS 'Group',[ID] AS 'Id'

FROM dbo.Table1

UION

SELECT [SectionGroup], [PartId]

FROM dbo.Table2

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy