Reputation: 91
I have to search for a particular word from two columns but in one column I have to search before * character. so I used SELECT * FROM table_name WHERE status = 'Enable' AND topic LIKE '%car%' OR category LIKE '%car%'
now the problem is it's returning beauty column also because it's category column has the word care, now I have to make it if the word contains before the first * it has to return.
+--------+---------------------------------------------------------------------------+---------+
| topic | category | status |
+--------+---------------------------------------------------------------------------+---------+
| car | cars & vechicles*cars* | Enabled |
+--------+---------------------------------------------------------------------------+---------+
| beauty | Fashion, Health & Beauty*Health and Beauty Products*Body Care / Skin Care | Enabled |
+--------+---------------------------------------------------------------------------+---------+
Upvotes: 0
Views: 281
Reputation: 65
You can make a simple modification to your query by adding "%*" like this:
SELECT * FROM table_name WHERE status = 'Enable' AND topic LIKE '%car%' OR category LIKE '%car%*%'
Upvotes: 0
Reputation: 790
This query should solve your problems:
SELECT * FROM table_name WHERE
status = 'Enable' AND topic LIKE '%car%' OR SUBSTRING_INDEX(category,'*',1) LIKE '%car%'
Upvotes: 1