I want to search exact word from string like
id Description
1 This is nice pen looking good
2 This is nice pendrive looking good
Search String : pen
My Current query
SELECT * FROM `table` WHERE Description like '%pen%';
Above Query return both record but I want Only first record. Because pen word exact match with my search string.
Expected Output
1 This is nice pen looking good
解决方案
Try using regular expressions:
SELECT
*
FROM
`table`
WHERE
Description regexp '(^|[[:space:]])pen([[:space:]]|$)';
SELECT
*
FROM
`table`
WHERE
Description regexp '[[:<:>:]]';