Let's say I have a table named food_prefs of friends and their favorite food(s).
| id | name | favorite_foods |
|---|---|---|
| 1 | Amy | Pizza |
| 2 | Bob | Pizza |
| 3 | Chad | Caviar |
| 4 | Dana | Pizza |
| 5 | Dana | Salad |
I understand how to get the names of everyone who likes pizza, but I'm unclear on how to select the people who only have pizza listed as their favorite food. That is, from the above table, I only want to select Amy and Bob.
Additionally, it would be great to have a solution that can also select names with multiple favorites (e.g. in another query select everyone who has pizza and salad as their favorite, which would). Finally, it could be useful if the pizza and salad query not only returned people who only liked both foods, but also people who only had one favorite that appears in that list (e.g. people who just like pizza or just like salad — everyone but chad in this example)
(I find the sqlite documentation not the most straightforward, so sorry if this is as a very straightforward question!)