在mysql中选择2个连接列,忽略所有空格

时间:2013-10-14 04:30:42

标签: php mysql

  

参考: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%"

它不会显示任何结果。

如何为此构建有效的查询?

1 个答案:

答案 0 :(得分:0)

SELECT CONCAT(fname, ' ', lname) 
     FROM people 
WHERE CONCAT(REPLACE(fname, ' ', ''), 
REPLACE(lname, ' ', '')) LIKE "%JohnCraigDeSmith%"