Search code examples
sqlsqlitewhere-clauseglobsql-like

Select by range of letters


Table students I am trying to sort by names for letters in range A-M:

Here is the table contents

Here is when i run the command

I've tried:

SELECT *  FROM student  WHERE student_first_name like '[A-M]%';

It's not giving me anything.


Solution

  • You are using SQLite which supports the GLOB operator where you can use the [x-y] list wildcard and * instead of %:

    SELECT * FROM student WHERE student_first_name GLOB '[A-M]*';
    

    Note that GLOB is case sensitive.

    If you want case insensitive results use:

    SELECT * FROM student WHERE UPPER(student_first_name) GLOB '[A-M]*';