Edit:
I realized I asked the question wrong. What I really meant to ask was, "given a set of values for [Column B]
, check if there is a value in [Column A]
that matches all of the set and no others."
I'm not sure if what I want to do has an official name, so searching for my question has been difficult.
Given a table with 2 columns and a list of values, I want to see if this combination (and only this combination) exists in the table.
For instance, given this table (assume it's the whole table):
|----------|----------|
| Column A | Column B |
|----------|----------|
| 12345 | abcde |
|----------|----------|
| 12345 | xyz |
|----------|----------|
| 12345 | abcd |
|----------|----------|
| 12345 | abbba |
|----------|----------|
And given this input parameter:
Declare @columnBs Varchar(Max) = '["abcde","xyz","abcd","abbba"]';
For that set, I want to return 12345
. So, basically, I want to run a check and see if any value in [Column A]
matches all of the values in [Column B]
to all of the values in @columnBs
AND NO OTHER VALUES.
Without a value for [Column A]
as a starting point, I'm having trouble even conceiving of a long-form solution.
If it helps to conceptualize this better, this is a solution for messaging where:
[Column A]
represents the thread's primary key[Column B]
represents a user assigned to the thread
So, if a new message comes in for a set of users, I want to see whether there is an existing thread for all of the users supplied by @columnBs
and no other users.