我正在尝试运行此查询但不运行
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = '1'pd.id = ng.post_id
ORDER BY ng.order
并收到错误
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在第1行'pd.id = ng.post_id ORDER BY ng.order'附近
我已经尝试过`ng.order`和`ng` .order`但仍然无法让它运行。
非常感谢任何帮助
答案 0 :(得分:2)
我认为你错过了and
:
AND ng.parent_id = '1'pd.id = ng.post_id
应该是:
AND ng.parent_id = '1'
AND pd.id = ng.post_id
或者更好的是,将连接条件放在连接中(除非它们确实是字符串,否则不要引用您的数字):
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng join `ecom_page_data` AS pd on ng.post_id = pd.id
WHERE ng.cluster_key = 'primary'
AND ng.tab = 0 -- Leave the quotes on if tab is a string
AND ng.parent_id = 1 -- Leave the quotes on if parent_id is a string
ORDER BY ng.order
答案 1 :(得分:1)
尝试
ng
。order
如果我可以在这个编辑器中显示反引号,那么它们就会存在,但它似乎会删除它们
反引号用于转义列名等中的保留字和空格
答案 2 :(得分:0)
将您的查询更改为('
放错了地方)
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = '1' AND pd.id = ng.post_id
ORDER BY ng.order
OR
SELECT ng.parent_id, ng.tab, ng.post_id, ng.ORDER, ng.cluster_key, pd.id, pd.slug, pd.link_text, pd.parent
FROM `ecom_navigation` AS ng, `ecom_page_data` AS pd
WHERE ng.cluster_key = 'primary'
AND ng.tab = '0'
AND ng.parent_id = 1 AND pd.id = ng.post_id
ORDER BY ng.order