How to select people like apple and banana both from the data below?
table: MyTable
persons | fruit
-----------------------------
P1 Apple
P1 Banana
P1 Mango
P2 Banana
P2 Apple
P3 Mango
P3 Apple
i.e in this case, P1, P2 should be the result.
I tried with
select * from MyTable where fruit in("Apple","Banana");
This is also resulting P3 because P3 also have apple.
Thanks for any help.
SELECT a.persons
FROM MyTable a JOIN MyTable b on a.persons=b.persons
WHERE a.fruit='Apple' and b.fruit='Banana'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With