J
Jon Davis
I need help with a SQL problem. This is "problem" as in like math problem.
(And no, this isn't for class, it's a contract that I've lost a lot of time
on by spending it pulling my hair out.)
I have a database with one catch-all table, something like as follows:
string Username
string Key
string SubKey
bool/bit BoolValue
int IntValue
A unique record is determined by Username + Key + SubKey.
I have two sets of many records. The first set looks like this:
[username], MyBoolValueRecord, [subkey], [1/0], [null]
The second set looks like this:
[username], MyIntValueRecord, [subkey], [null], [#number#]
The problem that I'm having is that I need the second set to be directly
corresponding the first set, so that I only retrieve the [subkey] +
[username] values of [key:MyIntValue] where [username] + [key:MyBoolValue] +
[subkey] is 1/true, and ignore the [subkey]+[username] values of
[key:MyIntValue] where [username] + [key:MyBoolValue] + [subkey] is 0/false.
Since I have to refer to separate records of the same table, I cannot use
JOIN (can I?). Surely this can still be done with a single SQL query? I can
settle with a stored procedure if I have to, but I'd prefer not. I've tried
WHERE ... IN (SELECT...), but that only supports one field match and I need
both [username] and [subkey] to match.
Sorry if this is hard to follow ... now you know my plight!!
Thanks,
Jon
(And no, this isn't for class, it's a contract that I've lost a lot of time
on by spending it pulling my hair out.)
I have a database with one catch-all table, something like as follows:
string Username
string Key
string SubKey
bool/bit BoolValue
int IntValue
A unique record is determined by Username + Key + SubKey.
I have two sets of many records. The first set looks like this:
[username], MyBoolValueRecord, [subkey], [1/0], [null]
The second set looks like this:
[username], MyIntValueRecord, [subkey], [null], [#number#]
The problem that I'm having is that I need the second set to be directly
corresponding the first set, so that I only retrieve the [subkey] +
[username] values of [key:MyIntValue] where [username] + [key:MyBoolValue] +
[subkey] is 1/true, and ignore the [subkey]+[username] values of
[key:MyIntValue] where [username] + [key:MyBoolValue] + [subkey] is 0/false.
Since I have to refer to separate records of the same table, I cannot use
JOIN (can I?). Surely this can still be done with a single SQL query? I can
settle with a stored procedure if I have to, but I'd prefer not. I've tried
WHERE ... IN (SELECT...), but that only supports one field match and I need
both [username] and [subkey] to match.
Sorry if this is hard to follow ... now you know my plight!!
Thanks,
Jon