Reputation: 491
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
Upvotes: 0
Views: 74
Reputation: 253
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.
Upvotes: 1
Reputation: 12378
Use this query
SELECT * FROM username_table WHERE username like 'john?[0-9]℅'
Upvotes: 0
Reputation: 1311
This should work
SELECT * FROM username_table WHERE username like 'john[^0-9]%' or username like 'john';
Upvotes: 0