忽略空格的查询

2021-11-20 00:00:00 postgresql sql database mysql

运行查询的最佳方法是什么,以便字段中的空格是无视?例如,以下查询:

What's the best way to run a query so that spaces in the fields are ignored? For example, the following queries:

SELECT * FROM mytable WHERE username = "JohnBobJones"    
SELECT * FROM mytable WHERE username = "John Bob Jones"

会找到以下条目:

John Bob Jones
JohnBob Jones
JohnBobJones

我使用的是 php 或 python,但我认为这无关紧要.

I am using php or python but I think this doesn't matter.

推荐答案

SELECT * FROM mytable 
    WHERE REPLACE(username, ' ', '') = REPLACE("John Bob Jones", ' ', '')

相关文章