pankajdaga
Programmer
Hi everyone,
I have not been in touch with SQL for a long time. I had to start using it again since a few weeks and it has been quite a struggle.
I have a question and I would be really grateful if someone can help me with it. Consider the following table structure:
ID TESTNUMBER STATE VALUE
1 100 1 0
2 100 1 1
3 100 2 1
4 100 2 0
5 101 1 1
6 101 1 0
7 101 2 1
Now, I have a code that has to generate all possible combinations of chosen States and Values.. Say for our example the combinations are (State = 1, 0) and (State = 2, 1).
Now, I have to go in the database and find the TestNumber which has an entry for (State = 1, 0) AND (State = 2, 0) (which would only be TestNumber 100. If I had used an OR in my Select query it would return both 100 and 101. Also, if I use AND for the same field it would return me nothing)... What SQL construct exists for performing such queries? I hope the question is not too vague. This is really urgent and I tried all of last night, but to no avail. Please help!
Thanks,
Sincerely,
Pankaj
I have not been in touch with SQL for a long time. I had to start using it again since a few weeks and it has been quite a struggle.
I have a question and I would be really grateful if someone can help me with it. Consider the following table structure:
ID TESTNUMBER STATE VALUE
1 100 1 0
2 100 1 1
3 100 2 1
4 100 2 0
5 101 1 1
6 101 1 0
7 101 2 1
Now, I have a code that has to generate all possible combinations of chosen States and Values.. Say for our example the combinations are (State = 1, 0) and (State = 2, 1).
Now, I have to go in the database and find the TestNumber which has an entry for (State = 1, 0) AND (State = 2, 0) (which would only be TestNumber 100. If I had used an OR in my Select query it would return both 100 and 101. Also, if I use AND for the same field it would return me nothing)... What SQL construct exists for performing such queries? I hope the question is not too vague. This is really urgent and I tried all of last night, but to no avail. Please help!
Thanks,
Sincerely,
Pankaj