oliverbj
oliverbj

Reputation: 6062

SQL - Select from database where ID is present more than x times

I have a table called users in my database, it have the following structure:

id (int)
username (varchar)
upline (int)

Now, if a user is a referral to another user, it's id will be insterted into upline

My question is, how can I search, generally across my entire users table, for the users who have the same id inserted into upline, without having a specific id?

Upvotes: 0

Views: 88

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271151

If I understand correctly, you basically just want a having clause:

select upline, group_concat(id)
from users
where upline <> 0
group by upline
having count(*) = 100;

Upvotes: 1

Related Questions