Sometimes our techie-brains convert a concept clearly articulated in plain English into unnecessarily mathematically expressed code. For example, "I want all records with an amount between 1000 and 1999" can become "x >= 1000 AND x <= 1999" But modern RDBMS database systems give us an English equivalent that saves translating the concept "between" into "greater than or equal to this, and less than or equal to that." It's the BETWEEN function, and it is the same across SQL Server, PostgreSQL, MySQL, and Oracle. Maybe others, too, but those are the ones that I have used in the past. BETWEEN is of the form: MyTestValue BETWEEN StartValue AND EndValue It is an inclusive comparison, equivalent to using >= and <= So these generate the same results: SELECT * FROM MyTable WHERE MyValue BETWEEN 100 AND 1000 vs SELECT * FROM MyTable WHERE MyValue >= 100 AND MyValue <= 1000 What are the advantages of BETWEEN? It's a
Musings on Tests, Quality, Tools, Projects and more. By Steve Page