奇怪:MySQL Left Join,“未知列”;相同的 leftjoin 在多表查询中不起作用

发布于 2024-12-15 01:21:24 字数 845 浏览 0 评论 0原文

我正在尝试运行选择查询,如下所示:

SELECT * FROM pages, c_item_category cc
LEFT JOIN pages_tr ON (pages.page_id = pages_tr.page_id AND lang_id = 2)
LEFT JOIN users ON (pages.page_author = users.u_id)
WHERE (pages.page_id = cc.item_id AND cc.cat_id = 7)
  AND (page_date >= 1317420000 AND page_date <= 1320101999)
  AND (page_showinfos = 1)
ORDER BY page_date ASC LIMIT 0,10

但我收到此错误:“on 子句”中的未知列“pages.page_id”

这是为什么?我可以确认“pages”中有一个名为“page_id”的列:)

但是,当我使用相同的左连接执行单表查询时,它运行良好:

SELECT * FROM pages
LEFT JOIN pages_tr ON (pages.page_id = pages_tr.page_id AND lang_id = 2)
LEFT JOIN users ON (pages.page_author = users.u_id)
WHERE (page_date >= 1317420000 AND page_date <= 1320101999)
  AND (page_showinfos = 1)
ORDER BY page_date ASC LIMIT 0,10

第一个查询中我的错误是什么? :\

I'm trying to run a select query, which is the following:

SELECT * FROM pages, c_item_category cc
LEFT JOIN pages_tr ON (pages.page_id = pages_tr.page_id AND lang_id = 2)
LEFT JOIN users ON (pages.page_author = users.u_id)
WHERE (pages.page_id = cc.item_id AND cc.cat_id = 7)
  AND (page_date >= 1317420000 AND page_date <= 1320101999)
  AND (page_showinfos = 1)
ORDER BY page_date ASC LIMIT 0,10

But I get this error: Unknown column 'pages.page_id' in 'on clause'

Why is that? I can confirm that I have a column named 'page_id' in 'pages' :)

But, when I do a single-table query with the same left joins, it works well:

SELECT * FROM pages
LEFT JOIN pages_tr ON (pages.page_id = pages_tr.page_id AND lang_id = 2)
LEFT JOIN users ON (pages.page_author = users.u_id)
WHERE (page_date >= 1317420000 AND page_date <= 1320101999)
  AND (page_showinfos = 1)
ORDER BY page_date ASC LIMIT 0,10

What is my mistake in the first query? :\

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

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

发布评论

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

评论(1

囍笑 2024-12-22 01:21:24

改为尝试这种方式。

SELECT *
FROM pages
LEFT JOIN pages_tr ON (pages.page_id = pages_tr.page_id AND lang_id = 2)
LEFT JOIN users ON (pages.page_author = users.u_id),
c_item_category cc
WHERE (pages.page_id = cc.item_id AND cc.cat_id = 7)
  AND (page_date >= 1317420000 AND page_date <= 1320101999)
  AND (page_showinfos = 1)
ORDER BY page_date ASC LIMIT 0,10

Try it this way instead.

SELECT *
FROM pages
LEFT JOIN pages_tr ON (pages.page_id = pages_tr.page_id AND lang_id = 2)
LEFT JOIN users ON (pages.page_author = users.u_id),
c_item_category cc
WHERE (pages.page_id = cc.item_id AND cc.cat_id = 7)
  AND (page_date >= 1317420000 AND page_date <= 1320101999)
  AND (page_showinfos = 1)
ORDER BY page_date ASC LIMIT 0,10
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文