The following sql query is not working.
select UserName
from [User]
where UserID Like
( select UserID
from UserRoles
where RoleID =
( select RoleID
from Roles
where RoleName='Manager'
)
)
Here we are working with 3 tables User, UserRoles, Roles. It shows the error as follows
Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.
The reason for the error is that a subquery is returning more than one row.
When you have a condition like
a = bor one witha LIKE b, both sides should be one item. If either side is a subquery, care should be taken that the subquery always returns either 0 or 1 row (and never more than one).You can rewrite with Joins or changing the
LIKEand the=toIN: