MySQL multi-condition query with AND keyword. In MySQL, you can use the AND keyword to connect two or more query conditions. Only records that meet all the conditions will be returned. SELECT * | {field name 1, field name 2, ...} FROM table name WHERE conditional expression 1 AND conditional expression 2 […… AND conditional expression n]; Query the student table, where the id field value is less than 16 and the gender field value is nv. It can be seen that the query conditions must be met before they are returned. Query the student table for records where the id field value is between 12, 13, 14, and 15, the name field value ends with the string "ng", and the grade field value is less than 80. It can be seen that the returned records satisfy the three conditional expressions connected by the AND keyword at the same time. PS: Let's take a look at MySQL multi-keyword multi-field fuzzy query Suppose there are two pieces of data: (table name is user) 1) username=admin, password=000000 2) username=admin, password=123456 The effect we want to achieve is to be able to enter multiple keyword queries, with multiple keywords separated by commas. Take the above table as an example: Entering the single keyword "admin" can find these two pieces of data, and entering "admin,000000" only finds the first piece of data. The sql statement that can be implemented is: select * from user where concat(username, password) like '%admin%'; select * from user where concat(username, password) like '%admin%' and concat(username, password) like '%000000%'; The function of concat is to concatenate strings, but there is a problem: if you enter a single keyword "admin000000", the first data will also be found, which is obviously not the result we want. The solution is: because multiple keywords are separated by commas, it means that commas will never become part of keywords, so we can solve this problem by separating each field with commas when concatenating strings. The following SQL statement will not query the first data: select * from user where concat(username, ',', password) like '%admin000000%'; If the separator is a space or other symbol, change ',' to 'separator'. Summarize: select * from table name where concat(field1, 'separator', field2, 'separator', ...fieldn) like '%keyword1%' and concat(field1, 'separator', field2, 'separator', ...fieldn) like '%keyword2%' ......; The above is the Mysql multi-condition query statement with And keyword introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Tutorial on using iostat command in Linux
>>: Detailed process of creating a VR panoramic project using React and Threejs
Lottie is an open source animation library for iO...
The datetime type is usually used to store time i...
Table of contents In JavaScript , we can usually ...
Supervisor Introduction Supervisor is a client/se...
Run cmd with administrator privileges slmgr /ipk ...
Recently, when I was sorting out the details of d...
After Vmvare sets the disk size of the virtual ma...
Find the problem Recently, when I was filling in ...
Today I was browsing the blog site - shoptalkshow...
Introduction to void keyword First of all, the vo...
Earlier, we used Docker to simply deploy the Spri...
Since Zabbix version 3.0, it has supported encryp...
Table of contents Preface 1. Arrange the installa...
I want to use the marquee tag to set the font scro...
<br />In previous tutorials of 123WORDPRESS....