The LIKE operator is used when you want to specify a condition for how a string is formatted.

For example, if you want to select all people whose names start with a D and end with an o:

select *
from Persona
where Nome like "D%o"

Two special characters can be used to indicate how a string is formatted:

  • %: indicates any number of any characters
  • _: indicates a single any character

A string LIKE "D_m" will be recognized only if it starts with the letter D, has any character in the middle, and ends with the letter m (e.g., Dom, Dvm, Ddm, etc.).

A string LIKE "%a__" will be recognized if it has any number of initial characters, then contains the letter a, followed by two additional any characters (e.g., Suvviaaa, Chefaii, etc.).


tags: databases SQL