A concise tutorial of SQL statements for Linux---like

Source: Internet
Author: User

like is another directive that will be used in the where clause. Basically, like allows us to find the information we need based on a nested pattern. In contrast, when we use in, we fully know the conditions we need, and when we use between , we make a list of them. The syntax for like is as follows:

Select "Field name"
From "Table name"
WHERE "field name" like {nested};

{nested} often includes wild cards (wildcard). Here are a few examples:

  • ' A_z ': All start with ' A ', another word of any value, and a string ending with ' Z '. Both ' ABZ ' and ' a2z ' conform to this pattern, and ' akkz ' does not conform (because there are two characters between A and Z, not a single word).

  • ' abc% ': all the strings beginning with ' ABC '. For example, ' ABCD ' and ' abcabc ' conform to this set of formula.

  • '%XYZ ': all strings ending with ' XYZ '. For example, ' wxyz ' and ' zzxyz ' all fit this set.

  • '%an% ': All strings containing ' an ' this set. For example, ' 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


    The results of Linux testing are as follows:




    Reprint please specify: Xiao Liu

  • A concise tutorial of SQL statements for Linux---like

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.