like is a directive that is used in the where clause.
Basically, like allows us to find the information we need based on a nested pattern.
In contrast, when using in, we fully know the conditions we need. When using between , we are listing a range. The syntax for like is as follows:
Select "Field name"
From "Table name"
WHERE "field name" like {nested};
{nested} often contains wild cards (wildcard). Here are a few examples:
' A_z ': All start with ' a ', and there's a word for whatever value. And a string ending with ' Z '. Both ' ABZ ' and ' a2z ' conform to this pattern, and ' akkz ' does not conform (since there are two characters between A and Z, not a single word origin).
' abc% ': all the strings starting with ' ABC '. For example. Both ' ABCD ' and ' abcabc ' conform to this set of formula.
'%XYZ ': all strings ending with ' XYZ '. For example. Both ' wxyz ' and ' zzxyz ' conform to this set.
'%an% ': All contain ' an ' this set of strings. For example. Both ' LOS ANGELES ' and ' SAN FRANCISCO ' match this set.We will use the last example above on our store_information form:
store_information Form
Store_name |
Sales |
Txn_date |
LOS ANGELES |
1500 |
05-jan-1999 |
SAN DIEGO |
250 |
07-jan-1999 |
SAN FRANCISCO |
300 |
08-jan-1999 |
BOSTON |
700 |
08-jan-1999 |
We enter.
SELECT *
From Store_information
WHERE store_name like '%an% ';Results:
Store_name |
Sales |
Txn_date |
LOS ANGELES |
1500 |
jan-05-1999 |
SAN FRANCISCO |
300 |
jan-08-1999 |
SAN DIEGO |
250 |
jan-07-1999 |
Linux results such as the following:
Reprint please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---like