MySQL - 在 WHERE 子句中使用 REPLACE()
MySQL - Using REPLACE() In WHERE Clause
我知道我可以通过使用 SELECT REPLACE(colm, ' ', '') FROM tbl
替换所有空格来 SELECT
列中的数据,但是如何在 WHERE
子句中执行此操作?这是我尝试过的:
SELECT things.*, stores.*
FROM things, stores
WHERE things.id = 283468234
&&
stores.name = "Some Name"
&&
REPLACE(LOWER(stores.owner), ' ', '') = "firstnamelastname"
我想要的结果示例是:
| things.id | stores.name | stores.owner |
|-------------|------------------|----------------------|
| 283468234 | Some Name | First Name Last Name|
我得到的错误是:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 25' at line 1
注意:我也尝试过使用 AND
而不是 &&
但没有任何改变
我认为我收到此错误的原因是 PHPMyAdmin 自动删除了我最后的 &&
语句,并添加了 LIMIT 0, 25
,使查询 SELECT things.*, stores.* FROM things, stores WHERE things.id = 283468234 && stores.name = "Some Name" && LIMIT 0, 25
。这是问题还是我的查询?我该如何解决这个问题?
&&
等同于SQL中的AND
。
确保 LIMIT 是您 SQL 语句中的最后一个子句。
您对 LIMIT 的使用也不正确。你想要:
LIMIT 25
返回 25 个结果
不是 LIMIT 0, 25
(结果 0 到 25 是你的意图,我想)。
根据您的原始陈述将所有内容放在一起:
SELECT things.*, stores.*
FROM things, stores
WHERE things.id = 283468234
AND stores.name = "Some Name"
AND REPLACE(LOWER(stores.owner), ' ', '') = "firstnamelastname"
LIMIT 25
虽然我没有测试过,但应该可以。
我发现了问题。看起来这纯粹是 PHPMyAdmin 的一个错误。我用我的软件尝试了 运行 查询,结果完美无缺。
我知道我可以通过使用 SELECT REPLACE(colm, ' ', '') FROM tbl
替换所有空格来 SELECT
列中的数据,但是如何在 WHERE
子句中执行此操作?这是我尝试过的:
SELECT things.*, stores.*
FROM things, stores
WHERE things.id = 283468234
&&
stores.name = "Some Name"
&&
REPLACE(LOWER(stores.owner), ' ', '') = "firstnamelastname"
我想要的结果示例是:
| things.id | stores.name | stores.owner |
|-------------|------------------|----------------------|
| 283468234 | Some Name | First Name Last Name|
我得到的错误是:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 25' at line 1
注意:我也尝试过使用 AND
而不是 &&
但没有任何改变
我认为我收到此错误的原因是 PHPMyAdmin 自动删除了我最后的 &&
语句,并添加了 LIMIT 0, 25
,使查询 SELECT things.*, stores.* FROM things, stores WHERE things.id = 283468234 && stores.name = "Some Name" && LIMIT 0, 25
。这是问题还是我的查询?我该如何解决这个问题?
&&
等同于SQL中的AND
。
确保 LIMIT 是您 SQL 语句中的最后一个子句。
您对 LIMIT 的使用也不正确。你想要:
LIMIT 25
返回 25 个结果
不是 LIMIT 0, 25
(结果 0 到 25 是你的意图,我想)。
根据您的原始陈述将所有内容放在一起:
SELECT things.*, stores.*
FROM things, stores
WHERE things.id = 283468234
AND stores.name = "Some Name"
AND REPLACE(LOWER(stores.owner), ' ', '') = "firstnamelastname"
LIMIT 25
虽然我没有测试过,但应该可以。
我发现了问题。看起来这纯粹是 PHPMyAdmin 的一个错误。我用我的软件尝试了 运行 查询,结果完美无缺。