1

我正在尝试运行此查询但没有运行

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` 但似乎仍然无法让它运行。

任何帮助深表感谢

4

3 回答 3

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
于 2011-10-17T04:07:28.467 回答
1

尝试

ng.order

如果我可以在此编辑器中显示反引号,那么它们会在那里,但似乎将它们删除

反引号用于转义列名等中的保留字和空格

于 2011-10-17T04:07:13.670 回答
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

或者

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
于 2011-10-17T04:08:22.760 回答