Another way of writing Like statements in SQL _ MySQL
Source: Internet
Author: User
For example, to search for all users whose usernames contain c, you can use usemydatabaseselect * fromtable1whereusernamelike % c %. The following is another way to complete the above function: usemydatabaseselect * fromtable1wherecharindex) in theory, this method has one more judgment statement than the previous method, that is, 0. However, for example, to find all users whose usernames contain "c", you can use
Use mydatabase
Select * from table1 where username like '% c %"
The following is another way to complete the above functions:
Use mydatabase
Select * from table1 where charindex ('C', username)> 0
In theory, this method has one more judgment statement than the previous method, that is,> 0, but this judgment process is the fastest. I want to believe that more than 80% of the operations are spent searching for words.
Character string and other operations, so it is no big deal to use the charindex function. this method also has advantages, that is, %, | cannot be used directly with like
The searched characters can be used directly in this charindex, as shown below:
Use mydatabase
Select * from table1 where charindex ('%', username)> 0
You can also write it as follows:
Use mydatabase
Select * from table1 where charindex (char (37), username)> 0
ASCII characters are %
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.