【发布时间】:2018-09-26 15:29:51
【问题描述】:
我知道我可以通过使用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。这是问题还是我的问题?我该如何解决这个问题?
【问题讨论】:
-
添加
&& LIMIT 0,25会导致任何查询出错,因为这是无稽之谈。 phpmyadmin 没有添加&&。也许将您的&&切换到AND看看是否可以清除它。 -
@JNevill 进行了编辑,很抱歉,
-
该错误与您添加
&& LIMIT...有关。现在您更改了代码,输出是什么?请记住根据您不断尝试的内容更改问题 -
你是什么意思“自动删除你的最后一个 &&
? Is the SQL you have in your question the EXACT sql you are submitting? I agree that Phpmyadmin is probably addingLIMIT 0,25` 到你的声明,但这不是导致错误的原因。 -
@JNevill 表示它变成了
SELECT things.*, stores.* FROM things, stores WHERE things.id = 283468234 && stores.name = "Some Name" && LIMIT 0, 25
标签: mysql sql replace where-clause