I have a many to many relationship within my database. For example I have a USER table
, a ROLE Table
, and USERINROLE table
. I have a search on my website that needs to find users in specified roles. For example I would like to retrieve User records who are in roles "reader" AND "writer"
My Query before the where looks like this:
SELECT * FROM User u INNER JOIN UserInRole ur ON
u.UserId= ur.UserId INNER JOIN Role r ON
Ur.RoleId = r.RoleId
the WHERE would be something like
WHERE roleid IN (1,2)
but that brings users in role 1 OR role 2 and I need them to be both Role 1 AND role 2
I need to retrieve the user row and the role row together for the ORM (Nhibernate)
Edit: I am using NHibernate so if there is a native way to do this, that would be awesome