tsql - Filtering records on a table data -


I have thus your desired output and input data to a table with tbl_contact_role table:

Contact_id ROLE_ID

1

1 to 2

1 to 3

2 1

2 2 < / P

3 3

4 3

Between the table figures above, I want the contact_id to have roles (1, 2), but not 3.

<. p> will be produced contact_id for the above data as 2 has two specific roles that the (1,2) and as mentioned above is not ROLE_ID 3 is

desired output: < / P>

Contact_id

2

Thanks in advance!

"itemprop =" text ">
  ContactRoles Where in role-id (1,2) COUNTID of group (* ) Select 2 being ContactID, except ContactID, where in role-id (3)  

or select from ContactID

  contact C1. C1.ContactID = C2.ContactID and C1.RoleID = 1 and C2.RoleID = 2 on ContactRoles C2 join left C1.ContactID = Where C3.ContactID and C3.RoleID = 3 C3.ContactID blank  


Comments