CVasquezG
CVasquezG

Reputation: 457

SQL search for string containing characters

I have a string "abc", and I want to search, in a SQL table, for the values that contain either a, b or c.

This is what I have right now:

Select * from TABLE where NAME like "abc" ;

This didn't work, but I know if I try something like

where Name like "a" or Name like "b" or ....

it will work.

Is there an easier way to do this? Since I don't want to separate my string into characters.

Upvotes: 0

Views: 88

Answers (3)

afzalex
afzalex

Reputation: 8652

You can use regular expression for this.
Have a look at the following :

Select * from TABLE where NAME REGEXP "[abc]";

Upvotes: 2

Iftikhar Ali Ansari
Iftikhar Ali Ansari

Reputation: 1760

select * from ab where name REGEXP '[abc]'

Upvotes: 2

Ubaid Ashraf
Ubaid Ashraf

Reputation: 875

This will do

Select * from TABLE where NAME like "%abc%" ;

For more check information here http://www.techonthenet.com/sql/like.php

Upvotes: -2

Related Questions