SQL query for Records containing a Character

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Sql
AI Thread Summary
To query records containing a specific character, such as 'c', in a field using SQL, the following patterns are used: for 'c' at the beginning, the query is "SELECT ... FROM table WHERE field LIKE 'c%'", where '%' acts as a wildcard. For 'c' at the end, the query is "SELECT ... FROM table WHERE field LIKE '%c'". If 'c' is located anywhere in the middle of the field, the correct query is "SELECT ... FROM table WHERE field LIKE '%c%'". This last pattern effectively captures all instances of 'c', including those at the beginning, middle, or end of the string, as '%' can represent an empty string.
WWGD
Science Advisor
Homework Helper
Messages
7,701
Reaction score
12,785
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:
Technology news on Phys.org
Yes, everything you have said is correct.
 
  • Like
Likes WWGD
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top