SQL UNION Question (or not UNION?)
- From: johnrou@xxxxxxxxxxxxxxxxxx
- Date: 11 Dec 2006 10:22:56 -0800
I've been struggling with a query for a couple of days, and I can't
seem to find a solution... so I thought I'd see if any of you have an
answer.
I am trying to write a search to pull information from a couple
different tables. Both tables contain similar information like
Last_Name, First_Name, and Middle_Name. Each table also contains
additional information. The first table contains an address for
example, and the second table contains an address and a phone number.
I need to write a SQL statement to get only the unique names from each
table, but also some sort of reference as to which table it came from.
UNION will work, but I can't tell which table it came from...
I need the return to give me the Name, plus a reference to the table
that it came from....... any ideas??
My thoughts so far...
SELECT DISTINCT Last_Name as LName, First_Name as FName, Middle_Name as
MName From Table1 UNION SELECT DISTINCT LastName as LName, FirstName as
FName, MiddleName as MName From Table2
Works great except I can't tell which table it came from.... any help
is appreciated....
.
- Follow-Ups:
- Re: SQL UNION Question (or not UNION?)
- From: Bob Butler
- Re: SQL UNION Question (or not UNION?)
- Prev by Date: Re: Text file SCHEMA
- Next by Date: Re: SQL UNION Question (or not UNION?)
- Previous by thread: Text file SCHEMA
- Next by thread: Re: SQL UNION Question (or not UNION?)
- Index(es):
Relevant Pages
|