Search code examples
sqlsqlitesubstringsubstr

SQLite substr function in WHERE expression


Suppose I have 'employee' table with 'lname' column

I am interested in fetching all rows, where second character can be either 'e' or 'o'

What i am doing wrong, this query doesnt return anything:

SELECT * FROM employee WHERE (substr(lname,2,3)='e' OR substr(lname,2,3)='o');

Solution

  • the third parameter in substr is the length, not the end character

    change to substr(lname,2,1)