Suppose you want to search a keyword in 5 different columns or almost in all the fields of the table, then MySQL
provides us with fulltext indexing and searching method.
Before using this method , you need to add FullText to the columns in which you want to search.
ALTER TABLE member ADD FULLTEXT(firstname, lastname,address);
Then comes your main query :
SELECT firstname, lastname,address FROM member
WHERE MATCH (firstname,lastname,address) AGAINST (’test’);
The Match will look for “exact match” in the above 3 columns and on successfull match it will return that row.
Suppose in member table there is a an entry with firstname = test then the output will be :
firstname lastname address
test abc xyz
Suppose you want to use wildcards then modify your query :
SELECT firstname, lastname,address FROM member
WHERE MATCH (firstname,lastname,address) AGAINST (’*test*’);