Tfouts
Tfouts

Reputation: 31

SQL search on part of column

Let's say I have multiple 6 character Alphanumeric strings. abc123, abc231, abc456, cba123, bac231, and bac123.

Basically I want a select statement that can search and list all the abc instances.

I just want a select statement that can list all instances with keyword "abc".

Upvotes: 3

Views: 136

Answers (4)

You can use LIKE operator in sql

  • Starting With Case

Select * From Table Where Column LIKE 'abc%';

  • Ending With Case

Select * From Tablo Where Column Like '%abc';

  • Contains With Case

Select * From Table Where Column LIKE '%abc%';

So If you want to use escape character in LIKE condition , you must make small changes on your condition

  • For Example :

    SELECT * FROM Table WHERE column LIKE '!%' escape '!';

More information for you is here

Upvotes: 0

Matt
Matt

Reputation: 15061

Use LIKE and wildcards %

SELECT *
FROM yourtable
WHERE yourfield LIKE '%abc%'

Input

yourfield
abc123
abc231
abc456
cba123
bac231
bac123

Output:

yourfield
abc123
abc231
abc456

SQL Fiddle:

Upvotes: 4

Jayanti Lal
Jayanti Lal

Reputation: 1185

 Select * from tablename
  where yourfield like 'yourconstantcharacters%'

Upvotes: 0

Shaymol Bapary
Shaymol Bapary

Reputation: 458

Could you try like this way

SELECT *
    FROM yourtable
    WHERE field LIKE '%a%' Or field LIKE '%b%' Or field LIKE '%c%'

Upvotes: 0

Related Questions