Best practice?
-
With the following table I am looking for suggestions on the best way to query the table for the follow criteria. ID SalesID FKey FValue 1 1 12345 1.25 2 1 555 2.25 3 1 775 3.00 4 2 432 2.00 5 2 12345 1.00 6 3 321 1.11 7 3 223 1.00 8 4 12345 1.25 9 4 775 3.00 10 4 222 1.00 I need to query the table for the SalesID number for the sales that sold both '12345' and '775'. This would be only SalesIDs 1 and 4. Querying FKey = '12345' OR FKey = '775' would return 1,2, and 4 and not just 1 and 4.
-
With the following table I am looking for suggestions on the best way to query the table for the follow criteria. ID SalesID FKey FValue 1 1 12345 1.25 2 1 555 2.25 3 1 775 3.00 4 2 432 2.00 5 2 12345 1.00 6 3 321 1.11 7 3 223 1.00 8 4 12345 1.25 9 4 775 3.00 10 4 222 1.00 I need to query the table for the SalesID number for the sales that sold both '12345' and '775'. This would be only SalesIDs 1 and 4. Querying FKey = '12345' OR FKey = '775' would return 1,2, and 4 and not just 1 and 4.
-
Can be done only using corelated subqueries
SELECT Distinct SalesID FROM fky a WHERE
EXISTS (SELECT * FROM fky b WHERE a.SalesID = b.SalesID AND fkey = 12345)
AND
EXISTS (SELECT * FROM fky c WHERE a.SalesID = c.SalesID AND fkey = 775)Regards KP