Table name: DocumentationBook
id | name_page |
---|---|
1 | rule1 |
2 | rule2 |
1 | rule3 |
2 | rule3 |
3 | rule2 |
3 | rule3 |
I have tried to do this,
SELECT COUNT(id)
FROM DocumentationBook
where name_page = "rule2" OR name_page = "rule3"
but it doesnt look right since i would like to show rule2 and rule3 following each other, or if there’s a method to give order of pages seen i would appreciate it so much.
2
Answers
I created a SQLFIDDLE using your table data;
The following query shall return you the expected result.
Output :
If you want to add this condition; you can add as
Here rule numbers you can decide as per your requirement.
This is a way to do it using
WITH
clauseFirst cte to get ids that have seen rule2 and rule3
Second cte to get ids that have seen other rules except rule2 and rule3
Then we get only ids from fist cte that are not on cte2.
Demo here