Reputation: 42380
I have several tables that have similar fields, for example, Name and Email address:
TABLE Users (
Name varchar(255),
Email varchar(255),
etc..
)
TABLE Clients (
Name varchar(255),
Email varchar(255),
etc..
)
TABLE Administrators (
Name varchar(255),
Email varchar(255),
etc..
)
I'd like to get a list of all names and email address, and be able to filter out duplicate addresses across tables (i.e. a client and a user may both have the same email address)
Upvotes: 0
Views: 89
Reputation: 57593
Well, you could try:
SELECT DISTINCT Name, Email FROM
(SELECT Name, Email FROM Users
UNION
SELECT Name, Email FROM Clients
UNION
SELECT Name, Email FROM Administrators) p
Upvotes: 2