Solved

sql server 2005 union  query where tables have some different columns

Posted on 2011-09-02
3
588 Views
Last Modified: 2012-06-22
I need to do  a union of two tables which have common columns but also have some different columns.
 union
any help appreciated...thanks
0
Comment
Question by:blossompark
3 Comments
 
LVL 19

Assisted Solution

by:Limbeck
Limbeck earned 100 total points
ID: 36472039
try a full outer join on first name and last name. but since it feels like im doing your homework thats all im gonna say ;)
0
 
LVL 5

Accepted Solution

by:
Angelgeo earned 400 total points
ID: 36472073

select
  [first name],
  [Last Name],
  [dept],
  [Service],
  null as age
from tableA
union all
select
  [first name],
  [Last Name],
  null as [dept],
  null as[Service],
  [age]
from tableB

Open in new window

0
 

Author Closing Comment

by:blossompark
ID: 36472094
Hi Limbec,
thanks for your input....not homework...just under a lot of pressure here to produce something and hard to think straight...

Hi Angelgeo,
thanks for that, saw something similar on google but was using NULL only as a column name  and didnt work...so I'll put in the "AS" and i'm sure it will be fine...
thanks again...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now