[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Simple distinct join of two tables in SQL

Posted on 2013-01-14
4
Medium Priority
?
850 Views
Last Modified: 2013-01-14
I know this has to be easy but honestly I dont have the time to figure it out.

I have two tables with a single column... LastName
Table A
Smith
Jones

Table B
Jones
Williams

How can I get a single result set... with distinct values... without using a temp table...

ie.
Smith
Jones
Williams

On a single table I would usually do "select distinct(LastName) from TableA"...

Thanks!
0
Comment
Question by:James Talvy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Expert Comment

by:wilcoxon
ID: 38775932
I don't have a good answer in sql for this.  I'd use a temp table, pipe it through Unix commands (I use sqsh for accessing Sybase), or whip up a quick perl script.
0
 
LVL 1

Author Comment

by:James Talvy
ID: 38775942
Can't do that since I need to use this as an intermediary step within a stored procedure...
0
 
LVL 11

Accepted Solution

by:
Simone B earned 1600 total points
ID: 38776035
Will this work?

select distinct LastName from TableA
union
select distinct LastName from TableB

Using DISTINCT eliminates duplicates within each table, while using UNION (instead of UNION ALL) should eliminate the duplicates between the two tables.
0
 
LVL 1

Author Closing Comment

by:James Talvy
ID: 38776144
Indeed it does seem to work thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

650 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