MySQL query results including lower bound in BETWEEN

Question:

How to select all names from the table, the first letter of which matches the range of letters from P to Z ?

I made the following request:

SELECT `name` FROM `table1` WHERE `name` BETWEEN 'Р' AND 'Я' ORDER BY `name`

In the resulting selection, there are no results in which name begins with the letter I , from which I concluded that BETWEEN selects values, including the first border (P), but not including the second border (I) in the result.

Is it possible to compose such a query so that names with the letter I also appear in the results?

Found this solution:

SELECT name FROM table1 WHERE name BETWEEN 'Р' AND 'Я' OR surname LIKE 'Я%' ORDER BY name`

But if suddenly someone proposes a more elegant solution, I will be happy to change my approach)

Answer:

probably not the entire field needs to be compared with a letter, but only the first character:

substring(name,1,1)

example:

SQL Fiddle

MySQL 5.6 Schema Setup :

create table t (n text);

insert into t values ('яблоки на снегу');

Query 1:

select * from t where n between 'р' and 'я'

Results:

Query 2:

select * from t where substring(n,1,1) between 'р' and 'я'

Results:

|               n |
|-----------------|
| яблоки на снегу |
Scroll to Top