I have a sql database table name law. Which have a column name title. I want to implement search operation using LIKE query. But when I search for male from title column it also returns female. One thing to notify that my title column contains multiple of words. But i dont want to see those rows which contains female word. I used wildcard for LIKE parameter.
SELECT * FROM `laws` WHERE title LIKE "male"
You need to include male and explicit exclude female from the text.
If you want the second line you need somewhat more complicated query
CREATE TABLE laws (title varchar(50))
INSERT INTO laws VALUEs ('Only for male partitipents'),('male and female partitipents'),('No more female partitipents in this law')
SELECT * FROM `laws` WHERE title LIKE '%male%' AND title NOT LIKE '%female%'
| title | | :------------------------- | | Only for male partitipents |
db<>fiddle here