mysql - 使用保留名称作为列名

发布于 2024-12-10 10:07:30 字数 532 浏览 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'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”,但似乎仍然无法让它运行。

非常感谢任何帮助

I am trying to run this query but doesn't run

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

and getting error

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 'pd.id = ng.post_id ORDER BY ng.order' at line 1

i've tried `ng.order` and `ng`.`order` but still cant seem to get it to run.

Any help is much appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荒芜了季节 2024-12-17 10:07:30

我认为您只是缺少 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

I think you're just missing an and:

AND ng.parent_id = '1'pd.id = ng.post_id

should probably be:

AND ng.parent_id = '1'
AND pd.id = ng.post_id

Or better, put the join condition in the join (and don't quote your numbers unless they really are strings):

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
故事还在继续 2024-12-17 10:07:30

尝试

ng.order

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

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

try

ng.order

if i could get backticks to show in this editor, then they would be there, but it seems to remove them

backticks are used to escape reserved words and spaces in column names etc

不美如何 2024-12-17 10:07:30

将您的查询更改为(您的 ' 放错了位置)

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

Change your query to (you have a ' misplaced)

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文