Reputation: 39
Please tell me the SQL statement to SELECT under the following conditions for the test table shown below.
test table layout
ID KEY VALUE
1 FOO A
2 BAR B
3 HOGE C
4
5
・・・
If VALUE of ID = 1 and KEY = FOO is equal to VALUE of ID = 2 and KEY = BAR, VALUE of ID = 3 and KEY = HOGE is returned.
If VALUE with ID = 1 and KEY = FOO and VALUE with ID = 2 and KEY = BAR are not equal, VALUE with ID = 3 and KEY = HOGE is returned.
Upvotes: 0
Views: 67
Reputation: 146349
Condition 1 and 2 are mutually exclusive: if 1 is true then 2 is not true, and vice versa. In both cases the desired outcome is ...
value C return
... so actually this query satisfies the requirement:
select value
from your_table
where ID = 3
and KEY = 'HOGE'
No doubt this is not the answer you want. Please you need to clarify your question.
Upvotes: 1