0
id | code |
12 | US   | 
12 | US   |
13 | US   |
13 | AZ   |
14 | US   |
14 | AZ   |

I want to return a column that says True if the code for every pair is same and false if not. Want to check for pairs of ids. All id values in the column are in pairs

Expected Result of this question

id | match |
12 | TRUE
13 | FALSE
14 | FALSE

Tried solving it similar to : Finding rows with same values in multiple columns but the answer was too long

0

1 Answer 1

3

Do a GROUP BY. If the max(code) = min(code), they are equal.

select id, max(code) = min(code)
from tablename
group by id

You can also use count() instead, for example if the rows don't come in pairs.

select id, count(distinct code) = 1
from tablename
group by id
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.