I would like to select only stores_id with more than one repo_id. In the case below, I would like as a result: Stores 1 and 4, as they have 2 repos_id related to them.
Example Table
| Stores_id | Repo_id | |-----------|----------| | 1 | 1 | | 1 | 2 | | 2 | 2 | | 3 | 1 | | 4 | 1 | | 4 | 2 | | 5 | 1 |
Advertisement
Answer
If I understand you Question correct here would be a small example with having:
create @test table ( stores_id int, repo_id int) insert into @test values (1,1), (1,2), (2,2), (3,1), (4,1), (4,2), (5,1) select store_id from @test group by stores_id having count(repo_id) > 1