Query output conditional upon values in dataset
I am pretending your table name is number_table. You query can be divided into two separate ones -- the first excludes rows with 10 in the test column and the second includes only one row with 10 in the test column. I assume the two queries are independent. From interpreting your question, I believe this query will do the job. 

SELECT * FROM number_table WHERE 
    (EXISTS(SELECT * FROM number_table WHERE number = 5 OR number = 6) AND EXISTS(SELECT chr FROM number_table WHERE chr = X) AND number &lt;&gt; 10) 
UNION 
SELECT * FROM number_table WHERE
 ((EXISTS(SELECT * FROM number_table WHERE number = 4 OR number = 5)) 
    AND NOT EXISTS(SELECT chr FROM number_table WHERE chr = X) AND number = 10
 ) LIMIT 1;