Reputation: 886
How do I match cut string from mysql
For exampe in the column the value is googleduo or googlehangout, but the string I have is google.
SELECT name FROM table WHERE name LIKE '%".$string."%' LIMIT 1
This doesnt return record. At least it return one by finding the closest time
OR maybe the case is vice-versa, I have string googleduo, but the value in the table is google. I want to return google.
Upvotes: 0
Views: 42
Reputation: 42844
if you need to check does the substring is present in the column value use one of:
SELECT name FROM table WHERE LOCATE(substring, name);
-- or
SELECT name FROM table WHERE INSTR(name, substring);
The functions returns the position of the substring in the column value if present and 0
otherwise. Non-zero is treated as TRUE, zero as FALSE.
The functions do absolutely the same and differs in parameters order only.
If you need backward condition then simply add NOT:
SELECT name FROM table WHERE NOT LOCATE(substring, name);
-- or
SELECT name FROM table WHERE ! LOCATE(substring, name);
Upvotes: 2