0

with this DB,

- id val1 val2
 - -----------------.
 - 1    num1   res1
 - 2    num2   res2
 - 3    num3   res3
 - 4    num4   res3
 - 5    num4   res3

I need to get only the records with duplicate values in val2, only if the information in val1 is different.

In this case, the output should be:

 - 3 num3 res3
 - 4 num4 res3

Nothing if the whole record is duplicate, e.g. 4 and 5 or if records are totally different. I'm using MS Access

Many thanks in advance

3
  • 2
    How come you want the row with id 4 instead of the one with id 5? Commented Jan 23, 2018 at 9:37
  • 1
    Are you using MySQL or MS Access? Commented Jan 23, 2018 at 9:37
  • Yes, you are right. the output could be also 3-4-5. Commented Jan 23, 2018 at 9:43

1 Answer 1

1

Do a self join. Return rows with same val2 but different val1.

select distinct t1.*
from tablename t1
join tablename t2
    on  t1.val2 = t2.val2
    and t1.val1 <> t2.val1
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.