WHERE and WHERE NOT in SELECT
How to use WHERE and WHERE NOT in the same SELECT SQL statement?
For example, I might have a table named fruit.
ID | Name | Colour
-------------------------
1 | Strawberry | Red
2 | Apple | Red
3 | Grape | Red
4 | Banana | Yellow
From this table, I can execute SELECT * FROM [fruits] WHERE Colour = 'Red'
and it will get this:
ID | Name | Colour
-------------------------
1 | Strawberry | Red
2 | Apple | Red
3 | Grape | Red
However, I would like to exclude Apple
from one query above, I could use WHERE NOT
, but this will return all fruits including Banana
.
How would I write a SQL query so that it would result in the next, selected color, but excluding a specific fruit:
ID | Name | Colour
-------------------------
1 | Strawberry | Red
3 | Grape | Red
I am using MsSQL 2014, any help would be appreciated.
+3
source to share
5 answers