1

I am trying to write SQL query to get records that have different values between the customer and the external columns.

login     customer    external
--------  ----------  --------
william   will200     will201
haymen    hay100      hay100
norman    nor345      nor346
bernie    ber23       ber23
william1  will100     will101     
max       max65       max65
norman1   nor789      nor790     

Output should be

login     customer  external
--------  --------  --------
william   will200   will201
william1  will100   will101
norman    nor345    nor346
norman1   nor789    nor790

I tried different queries but couldn't retrieve the desired output.

Any suggestions?

Thanks

3
  • I don't see what duplicates you are talking about. All the columns are unique. Commented Feb 3, 2017 at 0:21
  • sorry. i didn't explained clearly. Actually, customer and external columns are not same for each login from desired output. It should return rows only when values in customer and external columns are not same. Commented Feb 3, 2017 at 0:25
  • I edited your post to clarify the problem (what you wrote is exactly the opposite of what you want, as explained in your Comment). This is a very elementary question even for SO, where we get a lot of super trivial questions; what didn't work when you tried? You will learn more from sharing what you tried and didn't work, then from just getting a one line answer to your question. Commented Feb 3, 2017 at 0:31

1 Answer 1

1

I think your question is: "get records that DO NOT have duplicate values on 2 columns". This is based on your result set and sample data.

If so:

select t.*
from t
where login <> customer and  customer <> external and login <> external;

At the very least, this returns the rows for your desired results.

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.