I'm using SQLite for my database and what I need is get the list of the username based on a specific string
My query is
SELECT * FROM username_table WHERE username like 'john[^0-9]%'
Results are:
john1, johnny12, john123, johnatan12 ... (Except john I dont know why)
What i need is only john or john with any number besides him
Expected Result
john, john012, john1245, john1, john46...
Thank you
3 Answers 3
Have you tried using REGEXP operator? Following query works like a charm for data you've provided:
SELECT * FROM username_table WHERE (username REGEXP 'john[0-9]*');
Please note, it is case-sensitive.
Sign up to request clarification or add additional context in comments.
Comments
This should work
SELECT * FROM username_table WHERE username like 'john[^0-9]%' or username like 'john';
answered Feb 27, 2015 at 18:14
alsabsab
1,3713 gold badges17 silver badges33 bronze badges
3 Comments
Stack Exchange Broke The Law
@harpun "Not an answer" is for answers that aren't even attempts at answering the question.
alsabsab
what is the problem with my answer @immibis
Stack Exchange Broke The Law
@sabsab Nothing, another user flagged it as not an answer though.
Use this query
SELECT * FROM username_table WHERE username like 'john?[0-9]c/o'
answered Feb 27, 2015 at 18:06
Fahim
12.4k5 gold badges42 silver badges57 bronze badges
default
like 'john'will returnJohnatantoo