Previous Topic

Next Topic

SQL LIKE Extended Comparison Operator

The LIKE extended comparison operator indicates the similarity of one value as compared to another. The syntax is:

  Value [NOT] LIKE [Substitution_char] Comparison_value [Substitution_char]

Use the LIKE extended comparison operator to filter a table based on the similarity of a field value to a comparison value. Use of substitution characters allows the comparison to be based on the whole field value or just a portion. The following example returns all Customers where the CustomerName field is equal to Asheng Engineering Ltd:

  SELECT * FROM ARCUST WHERE CustomerName LIKE 'Asheng Engineering Ltd'

The wildcard substitution character % can be used in the comparison to represent an unknown number of characters. LIKE returns a TRUE when the portion of the field value matches that portion of the comparison value not corresponding to the position of the wildcard character. The wildcard character can appear at the beginning, middle, or end of the comparison value (or multiple combinations of these positions). The following example retrieves rows where the field value begins with 'A' and is followed by any number of any characters:

  SELECT * FROM ARCUST WHERE (CustomerName LIKE 'A%')

The wildcard substitution character _ (underscore) can be used to represent one unknown character. This can be used to return fields with an exact length. The following example retrieves rows where the field value begins with 'A' and is followed by three characters, represented by three underscore characters:

  SELECT * FROM ARCUST WHERE (CustomerName LIKE 'A___')

Use NOT to return the converse of a LIKE comparison. LIKE can be used only with string or compatible data types such as memo fields. The comparison performed by the LIKE extended comparison operator is case-sensitive.

See Also

SQL Extended Comparison Operators

Book Contents

Book Index