beOpen
 

SQL LIKE

LIKE is another keyword that is used in the WHERE clause. Basically, LIKE allows you to do a search based on a pattern rather than specifying exactly what is desired (as in IN) or spell out a range (as in BETWEEN). The syntax for is as follows:

SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN}

{PATTERN} often consists of wildcards. Here are some examples:

  • ‘A_Z’: All string that starts with ‘A’, another character, and end with ‘Z’. For example, ‘ABZ’ and ‘A2Z’ would both satisfy the condition, while ‘AKKZ’ would not (because there are two characters between A and Z instead of one).
  • ‘ABC%’: All strings that start with ‘ABC’. For example, ‘ABCD’ and ‘ABCABC’ would both satisfy the condition.
  • ‘%XYZ’: All strings that end with ‘XYZ’. For example, ‘WXYZ’ and ‘ZZXYZ’ would both satisfy the condition.
  • ‘%AN%’: All string that contain the pattern ‘AN’ anywhere. For example, ‘LOS ANGELES’ and ‘SAN FRANCISCO’ would both satisfy the condition.
 
sql_like.txt · Ultima modifica: 18/07/2006 21:12 da luca
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki