Using the Employee table, here are some examples of queries using numeric comparisons:
SELECT FirstName, LastName, Age FROM Employee WHERE Age = 24 OR Age = 25;
SELECT FirstName, LastName, Age FROM Employee WHERE Age >= 24 AND Age <= 25;
SELECT FirstName, LastName, Age FROM Employee WHERE Age BETWEEN 24 AND 25;
SELECT FirstName, LastName, Age FROM Employee WHERE Age IN (24, 25);
All these produce the same results:
FirstName |
LastName |
Age |
Phil |
Roach |
24 |
Andreas |
Smith |
25 |
Julia |
Allan |
25 |
You can exclude the above records, that is return everyone else, by reversing the logic with the NOT operator:
SELECT FirstName, LastName, Age FROM Employee WHERE Age NOT BETWEEN 24 AND 25;
SELECT FirstName, LastName, Age FROM Employee WHERE Age NOT IN (24, 25);
If you are chaining a series of conditions together, take care to use the parenthesis to denote the order the conditions are evaluated.
See also: