14

Below is an example of my membership table. There some records having multiple values in the email field. I only want to select those records that have multiple email values:

Member table

ID LASTNAME FIRSTNAME EMAIL
567 Jones Carol [email protected]
567 Jones Carol [email protected]
678 Black Ted [email protected]
908 Roberts Cole [email protected]
908 Roberts Cole [email protected]
908 Roberts Cole [email protected]

I would like the result to be:

567 Jones Carol [email protected]
567 Jones Carol [email protected]
908 Roberts Cole [email protected]
908 Roberts Cole [email protected]
908 Roberts Cole [email protected]

Notice that Ted Black is missing because he only has one entry for email address.

I should clarify that my membership table has more than 4 columns. There are additional columns for phone and address, etc. And there could be multiple entries for a member because he/she has more than one phone number or address. I only want to capture those individuals who have multiple email addresses.

This is part of a database cleanup and a primary key will be added. I should clarify further that some persons could have multiple entries with same email address. At this phase I don't want to capture those multiple entries with the same email address but only those have who multiple entries with different email address.

asked Jul 25, 2015 at 23:34

2 Answers 2

12

You could do something like:

select distinct x.id, x.lastname, x.firstname, x.email
from t as x
join (
 select id
 from t
 group by id
 having count(distinct email) > 1
) as y
 on x.id = y.Id 
Paul White
95.4k30 gold badges440 silver badges689 bronze badges
answered Jul 25, 2015 at 23:49
0
3
select x.* 
from member as x
where x.id IN
 (
 select id
 from member
 group by id
 having count(distinct email) > 1
 )
Colin 't Hart
9,51015 gold badges37 silver badges44 bronze badges
answered Jul 27, 2015 at 17:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.