mysql查询和全文中的Concat()
语法快要死我了!下一个查询有问题:
$cadbusca="SELECT * , MATCH (nombre, apellido, email, about, place, CONCAT(nombre,' ',apellido)) AGAINST ('$busqueda') AS Score FROM user WHERE MATCH (nombre, apellido, email, about, place, CONCAT(nombre,' ',apellido)) AGAINST ('$busqueda') ORDER BY Score DESC";
错误:
查询失败:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在
'(nombre,' ',apellido)) AGAINST ('dan stern') AS Score FROM user WHERE MATCH (nom'
附近使用的正确语法在第 1 行。
“dan stern” 是搜索的词...
The syntax is killing me! the next query is having problems:
$cadbusca="SELECT * , MATCH (nombre, apellido, email, about, place, CONCAT(nombre,' ',apellido)) AGAINST ('$busqueda') AS Score FROM user WHERE MATCH (nombre, apellido, email, about, place, CONCAT(nombre,' ',apellido)) AGAINST ('$busqueda') ORDER BY Score DESC";
Error:
Query failed: 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
'(nombre,' ',apellido)) AGAINST ('dan stern') AS Score FROM user WHERE MATCH (nom'
at line 1.
"dan stern" are the words searched...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使用
MATCH/AGAINST
执行全文搜索,您必须在要搜索的字段上有全文索引。请参阅匹配/针对文档。话虽如此,您试图在您的
MATCH
中包含一个动态实体CONCAT(nombre,' ',apellido)
,这是不允许的 - 您可以在这样的动态字段上没有索引。来自全文限制文档:
To perform a fulltext search using
MATCH/AGAINST
, you must have a full-text index on the fields you want to do the search on. See match/against doc.Having said that, you're trying to include a dynamic entity,
CONCAT(nombre,' ',apellido)
, in yourMATCH
, which is not allowed -- you can't have an index on a dynamic field like that.From the Full-Text Restrictions doc:
您需要创建一个类似于您想要的 concat 命令的列并对其进行索引。 (正如 Riedsio 所指出的)。另外,如果您的 where 子句中有匹配项,则无需执行“ORDER BY”,因为它会自动为您排序。
http:// www.devarticles.com/c/a/MySQL/Getting-Started-With-MySQLs-Full-Text-Search-Capability/2/
You'll need to create a column which is like the concat command you want and index against it. (As noted by Riedsio). Also, if you have the match in your where clause you don't need to do an 'ORDER BY' since it automatically sorts it for you.
http://www.devarticles.com/c/a/MySQL/Getting-Started-With-MySQLs-Full-Text-Search-Capabilities/2/