MySQL Query String contains with examples
Today in this article, we will see how to use MySQL query string contains with few examples.
MySQL Query String contains with examples
Query Pattern
SELECT
`COLUMN-A` ,
FROM `TABLE-O`
WHERE `COLUMN-B`
LIKE '%<search-fields>%'
Above, we are getting the columns COLUMN-A where “COLUMN-B” contains <search- fields> from MySQL table TABLE-O
Example
SELECT
`post_name` ,
`post_title`
FROM `_ZRZ_posts`
WHERE `post_content`
LIKE '%mailkit%'
In the above example, we are getting all the website post details where the post contains matching fields called “mailkit“.
MySQL string contains multiple words
We can verify mysql contains multiple values query as below.
One can use the OR or AND operator to combine multiple values as needed.
Example
SELECT `post_name` , `post_title` FROM `_ZRZ_posts` WHERE `post_content` LIKE '%mailkit%' OR 'smtp';
SELECT `post_name` , `post_title` FROM `_ZRZ_posts` WHERE `post_content` LIKE '%mailkit%' AND 'smtp';
In the above example, we get the names of all posts where the post contains matching fields called “mailkit” or “SMTP” in the content.
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.