Title - BETWEEN SQL operator Tags - sql operators programming

The BETWEEN operator is used in a WHERE clause to filter the result set within a range.

It accepts two values - the beginning and end of the range - as numbers, text, or dates.

Numbers example:

SELECT * FROM movies WHERE year BETWEEN 1990 AND 1999;

Returns only movies with years from 1990, up to and including 1999.

For text values, BETWEEN filters results to within the alphabetical range.

Text example:

SELECT * FROM movies WHERE name BETWEEN ‘A’ AND ‘J’;

Would return movies with a name that begin with the letter A, up to and NOT INCLUDING those that being with J.

However, if a movie’s name were just J, it would match and show in the results.

That’s because BETWEEN goes up to the second value - i.e. up to J - so the movie J would be included but Jaws wouldn’t.