I have DB with the following values
! # ! FROM ! TO !
!===!======!=======
! 1 ! aaaa ! aabb !
! 2 ! aa10 ! aa2a !
! 3 ! bb ! cc !
! 4 ! bb 20! bb 30!
! 5 ! bccc ! bccd !
FROM and TO can span any range. All suported charachters are allowed. FROM and TO can have different length. The DB has ~800’000 rows. The rows have mor columns which are important for the use case.
For an autocomplete field I have to find all records which do match somewhere between (including) FROM and TO.
I tried something like this:
SELECT *
FROM table WHERE (
'11' BETWEEN from AND to
)
Unfortunately this does not match for FROM=1105 and TO=1110 .
How would the correct query for this look like?
Edit: The question was changed a bit, so replacing the answer since I’m at 0 anyway 🙂
What you want is something similar to; (‘b’ being the string searched for, note it’s mentioned twice in the question)
Of course if you know the string you’re searching for and the length of it, you can replace the
CHAR_LENGTH()in actual code.Demo here