Beginning SQL learner here. I have the following database ‘drink_name’ with drinks (taken from Head First SQL):
| Blackthorn |
| Blue Moon |
| Oh My Gosh |
| Lime Fizz |
| Kiss on the Lips |
| Hot Gold |
| Lone Tree |
| Greyhound |
| Indian Summer |
| Bull Frog |
| Soda and It |
This is the ‘drink_name’ column. Then I have another column with ‘main’ ingredients. Among them soda, iced water, etc etc.
I’m playing around and I came upon the following query:
SELECT drink_name FROM easy_drinks WHERE main <> 'soda' OR main <> 'iced tea';
And I’m trying to understand why this query returns EVERY entry. What’s the logic behind this? I know if I wanted to have only the ones without those ingredients I can use AND, and then only the ones without soda or iced tea would come up, but this one I’m puzzled about.
Thanks.
>Solution :
This has not much to do with SQL, it’s simple boolean logic: your condition is always true. The same way that x <> 1 OR x <> 0 is true for any number, main <> 'soda' OR main <> 'iced tea' will be true for any value of main.
Or maybe you didn’t know that WHERE TRUE returns every entry in SQL?