I am building a digital bookshelf with various ways to display the books. Within this, I have a page to display data on the books, no. of pages read, and a page where have a table with the books being currently read.
Things were going well when I noticed that sometimes the books or data that I want to be displayed do not appear.
table ("") as Cover, Author as Author, Type as Type, ("*100)) + "/)") AS Progress
from "Books"
where Status = "Reading" AND contains(Type, "Fantasy") OR contains(Type, "Sci-fi") OR contains(Type, "Literature")
sort file.name ASC
The query for the second screenshot
TABLE sum(rows.Pages) as NumberOfPages
FROM #book
GROUP BY Year
In addition to what @anon63144152 is saying, I would like to add that using icontains() would do in-case sensitive matching against the types.
Another interesting aspect with your WHERE clause can be illustrated with the following queries:
F and T: `= false and true`
==F and F OR T: `= false and false or true`==
T and F: `= true and false`
T and (F or T): `= true and (false or true)`
contains(), AbC vs aBc: `= contains("AbC", "aBc") `
icontains(), AbC vs aBc: `= icontains("AbC", "aBc") `
Which displays as:
The highlighted line illustrates the case where the Status is not reading, aka false, it’s not Fantasy but it is Sci-fi. This, I reckon, should not return a true status since you’re not reading that book currently.
The issue I’m getting at is that the logic I’m assuming you want is that the query should only return those having both a status of reading, and either of the allowed types. To achieve this, you need to add parentheses around the various OR clauses, as elsewise a random true statement in the latter list will make the entire clause true, as illustrated in the example above.
I’m not saying your overall query will fail due to this, but you’ll get some false positives every now and then when not reading a book which is one of the accepted types.
@anon63144152 yes, it was because of that typo! Now it works fine, thanks a lot.
@juanbretti and @holroy thanks for the advice on improvement in the query. Now it is working much better.
Note: I also fixed the second issue. I was thrown back by the fact that 2021 appeared on one query and not on the other. Then I realized the the pages per year is a sum, so obviously there was missing data on some files.