0

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)

GSto
  • 41,512
  • 37
  • 133
  • 184

1 Answers1

2

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
Marco
  • 56,740
  • 14
  • 129
  • 152
  • 1
    @SashiKant: no, it doesn't!! Did you try it? – Marco Dec 07 '11 at 14:03
  • 2
    @SashiKant: no, if you copy my query you won't get that error, absolutely not!! Now I've also tested it, so be sure it's correct :) – Marco Dec 07 '11 at 14:09
  • No actually I tailered it, according to the tables i m having, its working now, thanks... hey plz help me with this query http://stackoverflow.com/questions/8416117/create-table-constraint-in-mysql – Sashi Kant Dec 07 '11 at 14:14
  • @SashiKant: I don't understand: question is yours? Or is from @GSto? – Marco Dec 07 '11 at 16:18