The BETWEENÂ operator allows us to select values within a range.
Syntax :
This will select all rows whose column has a value between 'value1' and 'value2'.
Let's create the table we will use for our examples:
Script:
Check the table to see the data and the structure.
Very good
Example 1:
say you want to get all the names that have ID values between 1 and 3.
Note: depending on the database you use the names that carry the values used in the condition may be listed or not, In our case they appear.
-this is when we use a numeric value.
Example 2 :
-now we will use string values:
see that we have 5 names listed and 6 names in our table
How does the BETWEEN operator works with strings ?
-well he will chose all the names that are between alphabetically.
so we see that Eve=E and Mike=M all names that are found in a,b,c,e...---... m...z will be selected.
-for use to understand more this concept we will create table that will have the alphabet letters, not all of them but in the same alphabetical order.
Here is the script
Ok now , after creating the table let's use the between operator.
Example :
-we see in this query brings all the letters from a-b;
Example :
now in this case thou we do not have all the letter that might be between a-x the query will bring all the letter that GO between the declared values , in our case a-x;
We can also use date as values in our between operators.