连接表上的单力索引抛出错误

时间:2017-02-07 18:13:39

标签: php mysql mysql-error-1064

我正在尝试使用左连接来桥接两个表并强制索引仅存在于连接表上的索引,但是我收到以下错误:

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近'FORCE INDEX(l.sfdcId)WHERE l.sfdcId ='003A000001eR0HsIAK'   在第3行订购a.activity

这是正在运行的查询的输出(如果我删除FORCE INDEX,则工作正常):

SELECT a.activityDate,a.primaryAttributeValue,a.attributeDescription,l.firstName,l.lastName,l.title,l.email
FROM activities AS a LEFT JOIN
     leads AS l 
     ON a.leadId = l.leadId FORCE INDEX (l.sfdcId) 
WHERE l.sfdcId = '003A000001eR0HsIAK'
ORDER BY a.activityDate DESC 

知道为什么会失败吗?

1 个答案:

答案 0 :(得分:1)

FORCE INDEX跟在表定义之后:

SELECT a.activityDate,a.primaryAttributeValue,a.attributeDescription,
       l.firstName,l.lastName,l.title,l .email
FROM activities a LEFT JOIN
     leads l FORCE INDEX (sfdcId)
     ON a.leadId = l.leadId 
WHERE l.sfdcId = '003A000001eR0HsIAK'
ORDER BY a.activityDate DESC ;