The problem with your original query is you are asking to return results where the
PermissionId is equal to two values at the same time – meaning the same row – this is impossible.
However you can get return the
UserID that has both
PermissionId =5 AND
PermissionId =7 by using a
GROUP BY with a
SELECT userId FROM UserPermissions up WHERE PermissionId IN (5, 7) GROUP BY userId HAVING COUNT(DISTINCT PermissionId) = 2