randombits
randombits

Reputation: 48450

sql where condition

I'm using MySQL 5.5 and have a table that has two columns user_1, user_2.

I want to SELECT every instance where the value of user_1 and the value of user_2 are the same at least two or more times.

So if a dataset has for instance:

user_1 | user_2 foo | bar foo | xzy abc | der foo | xzy abc | der abc | def

in this particular case, we'd have two matches, and that's where user_1 is equal to foo and user_2 is equal to xzy as well as where user_1 is equal to abc and user_2 is equal to der

Upvotes: 0

Views: 30

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269633

You can use group by and having:

select user_1, user_2
from t
group by user_1, user_2
having count(*) >= 2;

Upvotes: 2

Related Questions