EN VI

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

2024-03-12 18:00:05
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.

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, '%');

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login