0

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

hcarrasko
2,3526 gold badges34 silver badges46 bronze badges
asked Feb 27, 2015 at 17:59
2
  • Using like 'john' will return Johnatan too Commented Feb 27, 2015 at 18:10
  • @Hector yep I only need John with with/wothout numbers Commented Feb 27, 2015 at 18:11

3 Answers 3

1

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.

answered Feb 27, 2015 at 18:44
Sign up to request clarification or add additional context in comments.

Comments

0

This should work

 SELECT * FROM username_table WHERE username like 'john[^0-9]%' or username like 'john';
answered Feb 27, 2015 at 18:14

3 Comments

@harpun "Not an answer" is for answers that aren't even attempts at answering the question.
what is the problem with my answer @immibis
@sabsab Nothing, another user flagged it as not an answer though.
0

Use this query

SELECT * FROM username_table WHERE username like 'john?[0-9]c/o'
answered Feb 27, 2015 at 18:06

2 Comments

it still the same it renders johnny01, johnatan12 etc
0 Rows returned from: SELECT * FROM username_table WHERE username like 'john?[0-9]c/o'

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.