In general, use the MySQL in query to write this
The code is as follows |
Copy Code |
SELECT * From ' Tb_require ' WHERE ' require_id ' In (23, 1024) |
This method is generally suitable for numeric types, and if it is a string, enclose the single quotation mark. Such as:
The code is as follows |
Copy Code |
SELECT * From ' Tb_require ' WHERE ' Require_name ' In (' AAA ', ' bbbb ') |
When querying a string, you can use like plus% if you want to blur the match. Such as:
The code is as follows |
Copy Code |
SELECT * From ' Tb_require ' WHERE ' require_name ' like '%aaa% ' |
What if there is a need to query multiple strings with ambiguity? Like Plus in, how to write?
This time you can use the MySQL concat function
The code is as follows |
Copy Code |
SELECT * FROM Customers WHERE ' Robert Bob Smith III, PhD. ' Like CONCAT ('% ', name, '% ')
|
This solves the like-in problem.
Note that the concat need to be followed by parentheses, do not have spaces, there are spaces, may be the error OH.
Note that when you use SQL mode, you cannot use = or! =; use like or not to compare operators.
SELECT field from table WHERE a field like condition
With regard to conditions, SQL provides four matching modes:
1,%: Represents any one or more characters. Can match characters of any type and length.
Like what
The code is as follows |
Copy Code |
SELECT * FROM [user] WHERE u_name like '% III ' |
will be u_name as "John", "Zhang Cat Three", "three-legged Cat", "Tang Sanzang" and so on Have "three" records all find out.
Also, if you need to find a record in u_name that has "three" and "cat", use the and condition
The code is as follows |
Copy Code |
SELECT * FROM [user] WHERE u_name like '% III ' and u_name like '% Cat ' |
If you use
The code is as follows |
Copy Code |
SELECT * FROM [user] WHERE u_name like '% three% cat ' |
Although can search out "three-legged cat", but can not search out the conditions of the "cat three".
2,_: Represents any single character. Matches a single arbitrary character that is used to restrict the character-length statements of an expression: (you can represent a Chinese character)
Like what
The code is as follows |
Copy Code |
SELECT * FROM [user] WHERE u_name like ' _ Three _ ' |
Only find "Tang Sanzang" so U_name is three words and the middle one word is "three";
Another example
The code is as follows |
Copy Code |
SELECT * FROM [user] WHERE u_name like ' three __ '; |
Only find "three-legged cat" so name is three words and the first word is "three";