LIKE and NOT LIKE

LIKE and NOT LIKE

Written

Doing a search through data is easy enough when the equations produce a definite yes or no situation. There may be times though you will want to perform a more general search.

The LIKE and NOT LIKE have two search helper symbols. The underscore _ character that looks for one character and the percentage % character that looks for zero or more characters.

The query will only pick out the rows that provide a TRUE result according to the WHERE equation. The equation will equal the LIKE VALUE plus some possible extra characters afterwards. Example...

The query would search the address_book table and compare all of the data in the last_name column for any values starting with 'Stan' and ending with zero or more characters afterwards. The LIKE search is not case sensitive, so it will accept anything starting with 'stan' as well. The WHILE loop then prints out the results found if both equations are found TRUE.

Queries using the LIKE or NOT LIKE parameters may be a bit slower than a normal query search considering they are a broader value and do not take advantage of any indexing.

The underscore and percentage characters (also known as wildcard characters) can be used in front, at the end, or both ends of a value.

If you want to have an underscore or percentage character actually be part of the search value, put an escape slash \ in front of the character.

The underscore wildcard can be used a number of times to find a specific number of characters. Example, this would be used in an equation to return a value of 'Stan' plus 3 characters (since there are 3 underscores)...

As you may have guessed, the NOT LIKE parameter will do the opposite of LIKE. It will produce results that are NOT LIKE the specified criteria.

Table of Contents

Previous
CONDITIONALS