I am having some issues in trying to get my query to work. I am not that efficient with SQL Server.
I have a table that has an user id column and the user id matches different values in the type column so the data looks like this
User | Type
User1 | Soccer
User1 | Tennis
User1 | BasketBall
User2 | Tennis
User2 | Swimming
User3 | Soccer
User3 | Swimming
I want to be able to get all users that that belong to only one type (Soccer) but do not belong to any other types. So they should only have one type they belong to in the database.
SELECT [User] FROM Table1
GROUP BY [User]
HAVING COUNT([Type]) = 1
and max([Type])='Soccer'
and min([Type])='Soccer'
SQL FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With