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
ElasticSearch cluster supports動態請求的方式and靜態配置文件to ...
This article shares the installation tutorial of ...
When there are tens of thousands of records in th...
Of course, there are many people who hold the oppo...
Table of contents 1. Development Environment 2. I...
One day I found that the execution speed of a SQL...
Table of contents Introduction Download and insta...
MySQL 8.0.22 download, installation and configura...
This article example shares the specific code of ...
Table of contents 1. Custom instructions 1. Regis...
01. Command Overview The locate command is actual...
2048 mini game, for your reference, the specific ...
The detailed steps for installing mysql5.7.19 on ...
Table of contents introduction 1. MySQL master-sl...
Table of contents Using slots in Vue: slot Scoped...