Cyber Shadow
Cyber Shadow

Reputation: 15

Search for a specific letter in a specific spot within a varchar in SQL

I would like to search my database for any varchars with 'C' as the second letter.

I have tried "like '%C%'" but that returns values with C anywhere.

I am using mysql just in case that matters.

Upvotes: 1

Views: 1102

Answers (2)

Mauro Amarillo
Mauro Amarillo

Reputation: 1

This is another solution:

select *
from yourTable
where instr('c', yourColumn)!=2;

the instr() function returns an integer which indicates the position of the first occurrence of the substring in the first argument within the string on the second argument.

Upvotes: 0

Ike Walker
Ike Walker

Reputation: 65547

You can use _, which is the single character wildcard.

For example:

select *
from your_table 
where your_column like '_C%'

Upvotes: 2

Related Questions