By vice versa, I mean, check if any of the strings in a column contains the string.
Example:
String a = "Peperoni"
MySQL column:
{
"PPeperoni_123",
"roni",
"hello world"
}
It should return the first 2 rows.
(Note: im looking for the query string for this)
MySQL query string contains using INSTRINSTR(str, substr) function returns the index of the first occurrence of the substring passed in as parameters. Here str is the string passed in as the first argument, and substr is the substring passed in as the second argument.
$query = "SELECT * FROM my_table WHERE categories LIKE '2'"; $rows = mysql_query($query); This returns row if column only has value 2 but not 1,2,3 or 2,12.
MySQL LOCATE() Function The LOCATE() function returns the position of the first occurrence of a substring in a string. If the substring is not found within the original string, this function returns 0. This function performs a case-insensitive search. Note: This function is equal to the POSITION() function.
Check if String Contains Certain Data in MySQL Using the LIKE Operator in MySQL. Another alternative to find the existence of a string in your data is to use LIKE . This operator is used along with the WHERE clause to look for a particular string.
Not sure if I understand you correctly, but are you maybe looking for this:
SELECT ... WHERE column LIKE "%string%" OR string LIKE CONCAT("%", column, "%")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With