MySql like Query conversion method (like query is not required)

Source: Internet
Author: User
Tags mysql like query
Select * from account where userName like 'ad % '; select * from account where userName> = 'ad' and userName <' AE'

The results of these two queries are the same, and the efficiency seems to be similar. No specific efficiency test is conducted. If you are interested, you can test the efficiency.

In the like query, ad % is the data of userName starting with ad,

UserName> = 'ad' is used to query data starting with ad and also contains AE, af, ag ......, That is, to query data where "ad" contains d and is greater than d in "ad"

Therefore, and userName <'ad' ensures that the query interval is in "ad", while AE, af, ag ...... This data will not appear in the result set.

Of course, you can try:

Select * from account where userName> = 'ad' and userName <'az ';

Does the result set contain: AE, af, ag ...... Ak, al ...... Data starting with ay and az.

Related Article

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.