pykpyk:
I have a SQL dataset that looks like this:
SourceId SomeContent
-------------------
1 aaa
2 bbb
3 ccc
4 ddd
SourceId ConditionType CondidionValue
-------------------------------
1 1 2
1 2 200
2 1 3
2 2 201
3 1 4
I need to select the Sourceid that have matching specific key, e.g. (ConditionType=1 and ConditionValue=2) and (ConditionType=2 and ConditionValue=200 ) should return sourceId = 1). Query with specified key can match only one SourceId.
I'm trying to do it this way:
SELECT SourceId
FROM ConditionData
where ConditionType = 2 and ConditionValue = 200
and SourceId in(
SELECT SourceId
FROM ConditionData
where (ConditionType = 1 and ConditionValue = 2))
Is there more elegant query to get it?
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots