What I have
I’m working on an Android app with a menu of school canteens. I download data from a remote website and save them to the internal SQLite database to such table (SO Markdown doesn’t support tables, hence I’ll make it a list):
- ID
- TEXT – The name of the meal
- NUMBER – The number of the meal (we can choose from more)
- ORDERED – Boolean, whether the particular meal is ordered or not
- DATE – The date (timestamp) when the meal is server
(and a few more unimportant columns)
What I need
I want to provide the user with a list, where for every day when the canteen cooks there is either the meal he has ordered or information, that he hasn’t ordered anything for that day.
The question is, how should look my query when I need to get:
- Every date that is in the table (once).
- For each date either the info about the ordered meal, or (if there isn’t any ordered meal) something from which I can tell that the user will be hungry that day.
Because I want my users to be able to see also the meals they didn’t order (so that their friends can look, what they might have), I refuse to keep only the ordered meals.
Thanks in advance for any help.
The
GROUP BY "Date"ensures that you get one result per day; theMAX(Ordered)ensures that that result is one that is ordered, if possible.