连接列中有空格的表

时间:2015-06-19 01:03:04

标签: mysql sql

我似乎无法让这个工作。我有两个表要加入,但其中一个列在一些标题中有一个空格。我正在尝试以下代码并取得成功。

我还没有从加入的列中购买,因为我想测试我可以进行加入。

SELECT rcm.activitydatetime, rcm.'lead id', rcm.'new stage'
FROM customername_leads_by_lifecycle_stage_rcm AS rcm
INNER JOIN customername_leads AS leads
ON rcm.'lead id' = leads.ID;

我得到的警告是

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 ''lead id', rcm.'new stage' FROM customername_leads_by_lifecycle_stage_rcm AS rcm INNE' at line 1

任何帮助总是受到赞赏,谢谢!

1 个答案:

答案 0 :(得分:5)

对列名称使用反引号(`)而不是单引号(')

SELECT rcm.activitydatetime, rcm.`lead id`, rcm.`new stage`
FROM customername_leads_by_lifecycle_stage_rcm AS rcm
INNER JOIN customername_leads AS leads
ON rcm.`lead id` = leads.ID;

您也可以考虑重命名列,以便它们不会有空格。