I have this data.
tbl_data
id value
1 A
1 B
1 C
2 A
2 C
I want to select id which have 'A' and 'B' as value.
SELECT id FROM tbl_data WHERE value = 'A' AND value = 'B'
But it returns zero result.
How to make it to return id 1 ?
select id from table
where
value in ('A', 'B')
group by id
having count( distinct value ) = 2
Can you explain this part?
having count( distinct value ) = 2
Does it mean that if i want to select A, B, and C than it will become= 3
?Does it mean that if i want to select A, B, and C than it will become = 3
, Yes, that's correct@Yusufmm - just you need also
C
inwhere
clause too,where value in ('A', 'B', 'C')
Thank you very much.