Microsoft Access SQL Operators: LIKE |
|
Introduction |
The LIKE operator uses the wildcards to perform data analysis. To use it, you can use:
To use a LIKE operation in SQL, after the SELECT expression, type LIKE followed by the intended expression. When you apply the filter, all records that abide by the expression would be in the result. |
To find an exact string, type LIKE followed by the string in double-quotes. Here is an example: SELECT FirstName, LastName, Gender FROM Students WHERE LastName LIKE "Bidoula";
If the value you want to find is a date, include it between two # signs. Here is an example: SELECT FirstName, LastName, DateOfBirth, Gender FROM Students WHERE DateOfBirth LIKE #10/16/1991#;
To get a list of strings that include any characters as a substring in a string, use the * symbol. For example, if you do not know how the string starts but you know how it ends, type LIKE "*". Here is an example: SELECT FirstName, LastName, DateOfBirth, Gender FROM Students WHERE LastName LIKE "*son"; If you do not know how the string starts or how it ends but know one or more characters that it includes, surround the substring with * symbols. Here is an example: SELECT FirstName, LastName, DateOfBirth, Gender FROM Students WHERE LastName LIKE "*et*";
To specify that you want the strings that start with any character from o to r followed by anything, you would use LIKE "[o-r]*". Here is an example: SELECT FirstName, LastName, DateOfBirth, Gender FROM Students WHERE (((LastName) LIKE "[o-r]*")); In the same way, as stated already, you can use the * to the left, to the right or both. Also, you can combine the [] placeholder with the other wildcards.
To negate the filter of a range of characters, you can precede the LIKE operation with the NOT operator. Here is an example: SELECT FirstName, LastName, DateOfBirth, Gender FROM Students WHERE LastName) NOT LIKE "[c-w]*")); As an alternative, you can start the inside of the [] placeholder with !. An example would be LIKE "[!o-r]*". This would result in all records that do not start with o, p, or r.
To use specific characters, use the [] as the placeholder. Inside the square brackets, enter the characters separated by commas. Here is an example: SELECT FirstName, LastName, DateOfBirth, Gender FROM Students WHERE LastName LIKE "[a, h, o, y]*"; To negate the filter, you can precede the LIKE operation with the NOT operator. An example would be NOT LIKE "[a, h, o, y]*". As an alternative, inside the [] placeholder, start with the ! symbol. An example would be LIKE "[!a, h, o, y]*". In both cases, the list would include records that do not start with a, h, o, or y.
The * character on a LIKE operation is used to find many characters. If you want to find only one character, use the ? wildcard. For example, if you do not know by what character a string starts but know one or more characters after it, you can use ? followed by a substring. An example would be LIKE "?ane". This would produce such strings as Pane, Bane, or Sane. If you do not know by what character a string
starts, know the second character, but do not remember the rest of the
characters, you can combine the ? and the * symbols. Here is an
example:
|
|
||
Home | Copyright © 2008-2009 FunctionX, Inc. | |
|