2

I want to select rows whose values contain a string in a column.
For example, I want to select all rows whose values contain a string '123' in the column 'app'.
table:

app         id
123helper   xdas
323helper   fafd
2123helper  dsaa
3123helper  fafd
md5321      asdx
md5123      dsad

result:

app         id
123helper   xdas
2123helper  dsaa
3123helper  fafd
md5123      dsad

I am not familiar with SQL query.
Could anyone help me? .
Thanks in advances.

3 Answers 3

2

In a number of ways:

like:

select * from table
where app like '%123%'

rlike:

...
where app rlike '123'

instr:

...
where instr(app, '123')>0

locate:

...
where  locate('123', app)>0

Invent your own way.

Read manual: String Functions and Operators.

Sign up to request clarification or add additional context in comments.

Comments

2

Try the following using like

select
  *
from yourTable
where app like '%123%'

Output:

| app        | id   |
| ---------- | ---- |
| 123helper  | xdas |
| 2123helper | dsaa |
| 3123helper | fafd |
| md5123     | dsad |

Comments

2

Please use below query,

select app, id from table where app like '%123%';

Below are few additional information,

like '123%' --> Starts with 123
like '%123' --> Ends with 123
like '%123%'--> Contains 123 anywhere in the string 

Comments

Your Answer

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.