I want to search for products based on the entire name of the name as well as the name of the words. It is good to use LIKEto search for a product in mysql with UNION. My database is title(charchar(550)) = Colorzone Men Casual Wear Red Cotton Shirtnot Fulltext -
What is the best search algorithm for PHP and MYSQL?
But I need below the search result ( First : Cotton Shirtrecord, Second Cotton record and Third : Shirtrecord. Do not display all records mixed) as a single request
MYSQL query: For Ex: title =Cotton Shirt
SELECT title FROM zapstore_ecom_products WHERE title LIKE '%Cotton Shirt%' //Get Whole Title products.
UNION
SELECT title FROM zapstore_ecom_products WHERE title LIKE '%Cotton%' //Get list for first word Title products.
UNION
SELECT title FROM zapstore_ecom_products WHERE title LIKE '%Shirt%' //Get list for last word Title products.
Suppose a userβs title has 4 or more words, then he will make 4 or more queries using UNION. Will we make this search one query?
source
share