Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

My table contains a column name title. I want to sql search filter male and female from title column

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"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading