参考:LIKE query sql not working in concatenated values with space
样本表: **
--------------------------------------------------
| id | fname | lname | age
--------------------------------------------------
| 1 | John | Smith | 20
-------------------------------------------------
| 2 | John Craig | De Smith | 20
--------------------------------------------------
| 3 | John | De Smith | 20
--------------------------------------------------
MYSQL QUERY:
SELECT CONCAT(fname,' ',lname) FROM people WHERE CONCAT_WS(first_name,'',last_name) LIKE "%JohnCraigDeSmith%"
它不会显示任何结果。
如何为此构建有效的查询?
答案 0 :(得分:0)
SELECT CONCAT(fname, ' ', lname)
FROM people
WHERE CONCAT(REPLACE(fname, ' ', ''),
REPLACE(lname, ' ', '')) LIKE "%JohnCraigDeSmith%"