SQL like fuzzy query

Source: Internet
Author: User

In real-world project development, fuzzy matches are often needed, such as matching a part of a column value. SQL provides four methods of matching:

1,% matching

There are several different uses for% matching. %atm%, before and after all can be used to match, the result can be "atmmm", "Ggatm", "Bbatmaa";

select * from tableinfo where name like "%atm%";

If you need to match two characters or a string, you can connect with and.

select * from tableinfo where name like "%atm%" and name like "%bank%";

If you need to skip a string search.

select * from tableinfo where name like "%atm%bank%";

2. [] Match

Represents one of the characters listed in parentheses. Specifies a character or string, or range of numbers, and so on, requiring that the matched object be any of them.

select * from tableinfo where name like "atm[1、2、3]";

That is, you can only get a result set of ATM1,ATM2.ATM3 values.

3, ^] Match

Represents any one of the characters listed in parentheses. Specifying a character or string, or a range of numbers, and so on, requires that the matched object be any of the following except them.

select * from tableinfo where name like "atm[^1、2、3]";

That is, you can only get a result set other than the ATM1,ATM2.ATM3 value.

4, _ Match

Represents any single character.

select * from tableinfo where name like "_atm";select * from tableinfo where name like "atm_";

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SQL like fuzzy query

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.