Reputation: 2471
Using a SELECT
, I want to find the row ID
of 3 columns (each value is unique/dissimilar and is populated by separate tables.) Only the ID
is auto incremented.
I have a middle table I reference that has 3 values: ID, A, B.
How can I select the row ID when I only know the value of A and B, and A and B are not the same value?
Upvotes: 1
Views: 1640
Reputation: 115540
It's not very clear. Do you mean this:
SELECT ID
FROM middletable
WHERE A = knownA
AND B = knownB
Or this?
SELECT ID
FROM middletable
WHERE A = knownA
AND B <> A
Or perhaps "I know A" means you have a list of values for A, which come from another table?
SELECT ID
FROM middletable
WHERE A IN
( SELECT otherA FROM otherTable ...)
AND B IN
( SELECT otherB FROM anotherTable ...)
Upvotes: 1
Reputation: 86084
Do you mean that columns A and B are foreign keys?
Does this work?
SELECT [ID]
FROM tbl
WHERE A = @a AND B = @b
Upvotes: 2