Search code examples
sqlitesubstr

Select records with substr


In my table I have a column production with strings like 101014, 101015. I want to select all the records which end with 15. I asked with:

SELECT * FROM boxes where substr('production',5,2) = 15

or

SELECT * FROM boxes where substr('production',5) = 15

and nothing is returned..


Solution

  • SELECT * FROM boxes where production like '%15'
    

    Or if you want substr, instead of:

    SELECT * FROM boxes where substr('production',5) = 15
    

    try:

    SELECT * FROM boxes where substr(production,5) = '15'