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

I need to find if a string value is contained in a string in SQL

Good day coders,
I need to make a query where I find a manufacturer.name (For example: "Logistics") only when the name is contained inside a string (For instance: "Logistics spa").
How can I do this?

This is my manufacturer table model:

id name
0 Logistics
1 TE CONNECTIVITY

My database Engine is ISAM, and I’m using MariaDB as the main database.

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

For instance, I need to find the manufacturer.name contained in the string "CGS – TE CONNECTIVITY".

I tried this:

SELECT m.name FROM manufacturers as m WHERE m.name in ("CGS - TE CONNECTIVITY");

but of course, this won’t work the way it should.
My expected result should be in this case:

name
TE CONNECTIVITY

>Solution :

SELECT *
FROM manufacturer
WHERE ‘Logistics spa’ LIKE CONCAT(‘%’, name, ‘%’);

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