AGK
AGK

Reputation: 86

mysql query returning issue while using the comparison

I have a table with two fields

---------------
Qn  | ans
---------------
 1  |  2
---------------
 1  |  4 
---------------
 1  |  6 
---------------
 1  |  8 
---------------
 2  |  2
---------------
 2  |  4 
---------------
 2  |  6 
---------------

if am using the query to get the result as '1' but because of the value in 2 its returning 1 and 2.

SELECT qn FROM tbl T1 WHERE T1.ans IN (2,4,6,8)

i need the result 1 , is there any other method to get the result

Upvotes: 0

Views: 35

Answers (1)

juergen d
juergen d

Reputation: 204766

SELECT qn 
FROM tbl
WHERE ans IN (2,4,6,8)
group by qn
having count(distinct ans) = 4

Upvotes: 3

Related Questions