SQLite Forum

Inconsistency in BETWEEN Query
Login
You need to read up on data types is SQLite and the concept of "affinity".

See https://sqlite.org/datatype3.html#sorting_grouping_and_compound_selects

In section 4.2. Type Conversions Prior To Comparison, the second bullet is "If one operand has TEXT affinity and the other has no affinity, then TEXT affinity is applied to the other operand."

So you are performing a string (lexical) comparison of (duplicate digits removed for clarity) "40100" <= "4011" <= "40199", which is obviously true; because "4011" comes after any string beginning with "4010" and before any string beginning with "4019".