0

I have a table with the following structure:

Id  Email   Unsubscribed
1   email_1 0
2   email_2 0
3   email_3 1
4   email_1 1
5   email_4 1
6   email_3 0
7   email_1 0
8   email_4 1

I am trying to query for all duplicate emails that have different values in the Unsubscribed column. I want to return something like this based on the above example:

Email
email_1
email_3
3
  • GROUP BY, HAVING, COUNT DISTINCT etc. Commented Aug 12, 2019 at 13:39
  • the result email1 and email4 i would understand but why email3 ? Commented Aug 12, 2019 at 13:44
  • I wouldn't want email4 because it has the same Unsubscribed value in all instances. I would want email3 because it has varying values for Unsubscribed. Commented Aug 12, 2019 at 15:10

1 Answer 1

3

It think you just want this:

SELECT Email
FROM yourTable
GROUP BY Email
HAVING MIN(Unsubscribed) <> MAX(Unsubscribed);

The HAVING clause would only assert to true if a given email appeared with more than one value for unsubscribed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.