For example
testcolumn 7 contains two rows, if thenumbercolumn contains values 5 AND 6, AND the value is NOT X in thechrcolumn, I would like to select select the rows with 7 in thetestcolumn.For example
testcolumn 10 contains three rows, if thenumbercolumn contains values 5 AND 6, AND the value X exists in thechrcolumn, I would like to exclude rows with 10 in thetestcolumn.
The Demo of the below Schema and broken SQL query is available on SQL fiddle.
Schema:
CREATE TABLE TEST_DATA (ID INT, TEST INT, CHR VARCHAR(1), NUMBER INT);
INSERT INTO TEST_DATA VALUES
( 1 , 7 , 'C' , 5),
( 2 , 7 , 'T' , 6),
( 3 , 8 , 'C' , 4),
( 4 , 8 , 'T' , 5),
( 5 , 9 , 'A' , 4),
( 6 , 9 , 'G' , 5),
( 7 , 10 , 'T' , 4),
( 8 , 10 , 'A' , 5),
( 9 , 10 , 'X' , 6),
(10 , 14 , 'T' , 4),
(11 , 14 , 'G' , 5);
SQL:
SELECT *
FROM test_data t1, test_data t2
WHERE t1.number=5 is not t1.chr=X AND
t2.number=6 is not t2.chr=X;
How would it be possible to keep test column if number columns contains 5 and 6 and the chr column does not contain X?
UPDATE As result it should only be test column with 7, because test column 7 have 5 and 6 in the number column and not X.
UPDATE 2 Result example:
ID | TEST | CHR | NUMBER
1 | 7 | C | 5
2 | 7 | T | 6
the number column contains values 5 AND 6- this is not possible and would always return an empty result, since the same column in one row can not contain both5AND6. You probably meanOR?