SQL Tutorial


SQL SELECT
SQL DISTINCT
SQL WHERE
SQL AND OR
SQL IN
SQL BETWEEN
SQL LIKE
SQL ORDER BY
SQL Functions
SQL COUNT
SQL GROUP BY
SQL HAVING
SQL ALIAS
SQL JOIN
SQL OUTER JOIN
SQL Subquery
SQL UNION
SQL UNION ALL
SQL INTERSECT
SQL MINUS














Data Warehousing & Business Intelligence
Area Codes Info
State Info
HTML Tutorial




















Home
SQL Commands
Table Manipulation
SQL Syntax

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.
  • Let's use this last example on our Store_Information table:

    Table Store_Information
    store_name Sales Date
    LOS ANGELES $1500 Jan-05-1999
    SAN DIEGO $250 Jan-07-1999
    SAN FRANCISCO $300 Jan-08-1999
    BOSTON $700 Jan-08-1999

    we key in,

    SELECT *
    FROM Store_Information
    WHERE store_name LIKE '%AN%'


    Result:
    store_name Sales Date
    LOS ANGELES $1500 Jan-05-1999
    SAN FRANCISCO $300 Jan-08-1999
    SAN DIEGO $250 Jan-07-1999


    Next Section

    Site Map   |   Resources

    1