Solved

sql server 2005 union  query where tables have some different columns

Posted on 2011-09-02
3
591 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help Parsing a String with SQL Syntax 23 42
Extract string portion 2 24
Query to return total 6 18
SQL Server 2012 r2 - Query results have 2 seperate results instead of 1 2 22
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

775 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