Hi everyone. I am trying to make a selection from a set of tables, and I need to see the results when the Primary Contact is equal to (X username) OR when the Inside Sales Rep is equal to (X username) AND when its both, but when its both, i get duplicate values because it will show up twice (once for being the Inside Sales Rep, and once for being the Primary Contact). I am trying to refine the logic so that I only see a result when it is one or the other, and just ONE result from when it's both.
Here is the code
SELECT sr.servicerequestid, pc.ContactId , sr.InsideSalesRepId, sr.CompletedDate
From dbo.ServiceRequests sr
join dbo.StructureServiceRequests ss on sr.ServiceRequestId = ss.ServiceRequestId
join dbo.Structures st on ss.StructureId = st.StructureId
join dbo.Projects pr on st.ProjectId = pr.ProjectId
join dbo.ProjectContacts pc on pr.ProjectId = pc.ProjectId
join dbo.Users u on pc.ContactId = u.UserId
where pc.ContactId = 4784
or sr.InsideSalesRepId = 4784
So in that result set, you can see it returns multiple servicerequests for each result where either the InsideSalesRepId is X or the ContactId is X, and returns duplicates when its both.
Ideally I'd like to return DISTINCT servicerequestids, but the results are being selected as the entire table, and I am not going to spend all my time going through to individually group by every single column (this is already being used in the MVC this way).
I really hope this made sense, but I'd be happy to clarify any other questions. I've spent a lot of time trying to figure out this logic so I hope someone out there can help me out! Thanks