Need Help

  • There are 2 tables Users which containing userid and other user related data and other table is UserRoles which contains userid and roleid.

    I want to fetch users who do not have any roles assigned.

    i want to fetch large amount of data so if i use "not exists" or"NOT IN" then it affects performance  of query very badly.

    So please help me to get the required result with optimized query

    Thanks In advance,

    Ashwini K.

  • hi

    try this......

    select u.userid from users u left outer join userroles ur on u.userid = ur.userid

    where ur.roleid is null.

    "Keep Trying"

  • Be sure you have indexes on the join columns as well.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply