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

时间:2011-11-12 18:08:59

标签: mysql sql database left-join

我正在尝试运行一个select查询,如下所示:

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 clause'

中的未知列'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

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

1 个答案:

答案 0 :(得分:2)

请尝试这种方式。

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