Two Tables with a State want DISTINCT States of both Columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

HI

I have a data base with two tables. Each table contains a State column
I want one DISTINCT List of all states contained in either table
 
HI

I have a data base with two tables. Each table contains a State column
I want one DISTINCT List of all states contained in either table

A UNION query will do this:

SELECT State FROM TableA
UNION
SELECT State FROM TableB;

The UNION operator removes all duplicates (you can use UNION ALL if
you want the dups kept).

John W. Vinson[MVP]
 
Hi Herb,

I'd use two queries - one to put all States together from both tables, and
another to get the Distinct values:

AllStates:
SELECT State FROM [Table1] UNION SELECT State FROM [Table2]

DistinctStates:
SELECT DISTINCT State from AllStates
 
The UNION operator removes all duplicates (you can use UNION ALL if
you want the dups kept).

Never knew that - gee, you learn something new every day on here :)
 
Hi

Maybe I did not state my problem correctly. See the example below
The UNION finds the common states that is not what I had in mind

Table1 Table2
CA AZ
CA NY
ILL NY

Resulting list
AZ
CA
ILL
NY

Thanks in advance

Herb
 
Back
Top