I'm looking for a way to filter over two row conditions. In general in basic sql it's possible to use the where and or statements to filter the query. What if i want to filter over two rows. I want to find every patient in following example, which belongs to both of two groups.
If i use:
select * from table
where group = group1 and group = group2
obviously it's not working.
How can i query "find every patient with two specific group values"? In this example i'm looking for group1 and group2, so peter should not be matched, though he is in two groups.
Student
id | patient | group
1 | jhon | group1
2 | jack | group1
3 | jill | group2
4 | jack | group2
5 | jill | group1
6 | peter | group2
7 | peter | group3
Expected output (ordering not necessary):
Student
id | patient | group
1 | jack | group1
2 | jack | group2
3 | jill | group1
4 | jill | group2
It was mentioned, using "group" as column name is bad, that's true. I wanted to point this out, since i don't want to change the question.