在MySQL中匹配时替换

时间:2014-12-21 18:12:51

标签: mysql

artists

id | name
---------
1  | kida
2  | capital t
3  | taylor swift


select replace(name, ' ', '') from artists where match(`name`) against ('taylorswift' IN BOOLEAN MODE) limit 1

如果我运行此查询它没有显示结果,但我想用null替换空格并显示Taylor Swift作为结果。这可能吗?

1 个答案:

答案 0 :(得分:0)

那是因为taylorswift != taylor swift。您的主要想法是显示name没有空格。你可以这样做

select replace(name, ' ', '') as name
from artists 
where match(`name`) against ('taylor swift' IN BOOLEAN MODE) 
limit 1;