rsmithinfo
Programmer
My tables are little more complex but the example below explains my problem in more simple terms.
Table1
test_id
test_name
Table2
table2_id
test_id
test_questionyes1
test_questionyes2
I would like to select the distinct test_id's where all the rows in Table2 have questionyes1 set to 1 and there are no rows where test_questionyes2 is set to 1, so:
SELECT DISTINCT t1.test_id FROM Table1 t1 INNER JOIN Table2 t2 ON t1.test_id = t2.test_id where t2.test_questionyes1 = 1 and t2.test_questionyes2 = 0;
but that won't work for what I want it to return - it will return all test_ids that have test_questionyes1 set to 1, irrespective of if there are rows in table2 with t2.test_questionyes2 = 1.
e.g. there is a test_id 3 it has the following entries in Table2:
1 3 1 1
2 3 0 1
it should not return this test_id as there is a row where test_questionyes2 = 1 (the second row) but it will because the criteria are satisfied in the first row.
Does this make sense?
Table1
test_id
test_name
Table2
table2_id
test_id
test_questionyes1
test_questionyes2
I would like to select the distinct test_id's where all the rows in Table2 have questionyes1 set to 1 and there are no rows where test_questionyes2 is set to 1, so:
SELECT DISTINCT t1.test_id FROM Table1 t1 INNER JOIN Table2 t2 ON t1.test_id = t2.test_id where t2.test_questionyes1 = 1 and t2.test_questionyes2 = 0;
but that won't work for what I want it to return - it will return all test_ids that have test_questionyes1 set to 1, irrespective of if there are rows in table2 with t2.test_questionyes2 = 1.
e.g. there is a test_id 3 it has the following entries in Table2:
1 3 1 1
2 3 0 1
it should not return this test_id as there is a row where test_questionyes2 = 1 (the second row) but it will because the criteria are satisfied in the first row.
Does this make sense?