SQL UNION Question (or not UNION?)



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....

.



Relevant Pages

  • RE: Leading blanks being stripped
    ... FullName - FName, MName, LName ... FormalName - Prefix, FName, MName, LName, Degrees ...
    (microsoft.public.access.forms)
  • Re: SQL UNION Question (or not UNION?)
    ... MiddleName as MName From Table2 ... SELECT DISTINCT Last_Name as LName, First_Name as FName, Middle_Name ... FirstName as FName, MiddleName as MName, 2 as FromTable From Table2 ...
    (microsoft.public.vb.database)
  • Re: Create Table?
    ... Lyle Fairfield wrote: ... I have a table that has the following fields; LName, FName and ... MName. ...
    (comp.databases.ms-access)
  • Re: Create Table?
    ... DFS wrote: ... I have a table that has the following fields; LName, FName and MName. ...
    (comp.databases.ms-access)
  • Re: Form wont remember last value
    ... "Ken Snell (MVP)" wrote: ... "I am using the LName and FName parameters as the Control Source for ... Report SQL: ...
    (microsoft.public.access.formscoding)