SQL query for Records containing a Character

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Sql
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 1K views
Messages
7,819
Reaction score
13,151
Hi All,
I am trying to do an SQL query for records containing a certain character, say, c , in 'field'

I think if the character c is at the beginning, we use :

Select ... from table
where field like 'c % ' , where % is a wildcard.

Similar for cases where the character is at the end, i.e., we would use :

Select ... from table
where field like '% c '.

But if the character c was somewhere in the middle , would we use :

Select ... from table
where field like '% c % ' ?

EDIT: I assume the last choice, '% c % ' covers all cases, since % may stand for an empty string.
Is this correct?
Thanks.
 
Last edited:
Physics news on Phys.org
Yes, everything you have said is correct.
 
  • Like
Likes   Reactions: WWGD