how can i search for a particular string in mysql? I tried using contains- gives me error:
SELECT r.name
, r.network
, r.namestring
, i.name
, r.rid
, i.id
, d.dtime
, d.ifInOctets
, d.description
FROM router AS r
INNER JOIN interface AS i ON r.rid = i.rid
INNER JOIN 1278993600_1_60 AS d ON i.id = d.id
AND d.dtime BETWEEN 1279027200 AND 1279029000
WHERE r.network = "ITPN"
AND i.status = "active"
AND i.description CONTAINS ' DBK'
Please help.
MySQL query string contains using LOCATE We will be using the LOCATE() function for the solution. LOCATE(substr, str) function returns the first occurrence of the substring passed in as parameters. Here substr is the substring passed in as the first argument, and str is the string passed in as the second argument.
CONTAINS is a predicate used in the WHERE clause of a Transact-SQL SELECT statement to perform SQL Server full-text search on full-text indexed columns containing character-based data types. CONTAINS can search for: A word or phrase. The prefix of a word or phrase.
Try this query: mysql_query(" SELECT * FROM `table` WHERE `column` LIKE '%{$needle}%' ");
To check if string contains specific word in SQL Server we can use CHARINDEX function. This function is used to search for specific word or substring in overall string and returns its starting position of match. In case if no word found then it will return 0 (zero).
Try
AND i.description LIKE '% DBK%'
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