(I really struggle with how to ask this question correctly with few words, so sorry for the title. I tried my best.)
I have a database like this:
id | animal | date | no |
---|---|---|---|
1 | dog | blank | 0 |
2 | cat | blank | 0 |
3 | dog | 07/12 2021 | 3 |
4 | dog | 08/12 2021 | 2 |
5 | cat | 08/12 2021 | 4 |
(The table is a simplified table from a larger project in Android Studio with java.)
I want to query this datebase so that:
- I get the animals on a certain day
- If an animal is not given for å certain day, I want the row with that animal and a blank date
Examples:
- If date is 08/12 2021, I want rows with id 4 and 5.
- If date is 07/12 2021, I want rows with id 3 and 2 (no cat that day)
- If date is 06/12 2021 (or any other date), I want rows with id 1 and 2 (no cat nor dog that day)
I know I can get all from a certain date pluss those with blank dates, by:
@Query("SELECT *
FROM db
WHERE (db.date LIKE :date OR db.date LIKE :blank)
ORDER BY no ASC")
But, how can I get what I want instead?