Skip to content
Advertisement

How can I run this SELECT query?

I’m working on a Messaging feature for an application, and I have a the following tables in MSSQL, along with a User table (not listed):

I want to query the ThreadParticipant table for whether or not a thread exists containing only a given set of user ids, let’s say users 1,3,5,7. Each Thread contains a unique set of user ids. How could I query for this data? If it’s any simpler, I can put some of the logic in the server (node.js). I’ve looked for question duplicates online and can’t find any, though I’m not sure exactly how to phrase the question to locate them if they’re around.

Advertisement

Answer

You can use aggregation with a having clause:

EDIT:

If you want ONLY these users, then use:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement