Assume there are two types of data: (Table Name: user) 1) usernameadmin, password0000002) usernameadmin, password123456.
Assume there are two types of data: (Table Name: user) 1) username = admin, password = 000000 2) username = admin, password = 123456
Assume there are two data types:
(Table Name: user)
1) username = admin, password = 000000
2) username = admin, password = 123456
The effect we want to achieve is that you can enter multiple keywords for query. Multiple keywords are separated by commas.
Use the preceding table as an example: Enter the keyword "admin" to check the two data items. Enter "admin, 000000" to check only the first data. The SQL statement is as follows:
Select * from user where concat (username, password) like '% admin % ';
Select * from user where concat (username, password) like '% admin %' and concat (username, password) like '% 100 ';
Concat is used to connect strings, but there is a problem: If you enter the single keyword "admin000000", the first data will also be found. This is obviously not the result we want. The solution is: because multiple keywords are separated by commas, the comma will never be part of the keyword. Therefore, when connecting strings, we can separate each field with commas to solve this problem, the following SQL statement does not query the first data:
Select * from user where concat (username, ',', password) like '% admin000000 % ';
If the Delimiter is a space or other symbols, modify 'and' to 'delimi.
Summary:
Select * from table name where concat (Field 1, 'delimiter', Field 2, 'delimiter ',... field n) like '% keyword 1%' and concat (Field 1, 'delimiter', Field 2, 'delimiter ',... field n) like '% keyword 2% '......;