2012-01-28 79 views
0

我有點困惑在這裏需要一些幫助......如何INNER JOIN超過兩個類別?

的情況是我做了三個表(fr_Leagues,fr_nations和fr_confeds),我想要做的就是添加一個聯賽足見類別的名稱不是帶分頁的id。這裏是代碼:

現在固定!

"SELECT 
a.id as confed_id, 
a.fr_short_name as confed_name, 
    b.id as nation_id, 
b.fr_name as nation_name, 
c.id as league_id, 
c.fr_name as league_name" 
." FROM fr_confeds as a 
INNER JOIN fr_nations as b ON a.id = b.confed_id 
INNER JOIN fr_leagues as c ON b.id = c.nation_id" 
." LIMIT $paginate->start, $paginate->limit" 
+0

你可以發表你的表格架構嗎? – 2012-01-28 06:56:44

回答

3

您不知道如何將不同的表格連接在一起。在每個INNER JOIN,你需要把它:

INNER JOIN fr_nations ON a.<someColumn> = b.<anotherColumn> INNER JOIN fr_leagues ON a.<someColumn> = b.<anotherColumn> 
+0

你可以請更具體嗎? – HiroHito 2012-01-28 07:37:20

+0

收到這個錯誤: #1054 - 未知列 'C.league_id' 在 '上子句' 這是我加入: FROM fr_confeds爲A INNER JOIN fr_nations爲B ON A.id = B.confed_id INNER JOIN fr_leagues作爲C ON B.confed_id = C.league_id LIMIT $ paginate-> start,$ paginate-> limit – HiroHito 2012-01-29 04:24:59

+0

工作就像一個魅力,謝謝@hakre – HiroHito 2012-01-29 07:09:23

0

使用此查詢

SELECT * FROM fr_confeds爲A

INNER JOIN fr_nations爲B ON A.id = B.confed_id

INNER JOIN fr_leagues如C ON B.confed_id = C.league_id

LIMIT $ paginate->啓動,$ paginate->限制

+0

似乎不起作用.. – HiroHito 2012-01-28 07:37:07

+0

它顯示此錯誤: #1054 - 'on子句'中的未知列'C.league_id' – HiroHito 2012-01-28 19:05:46

+0

如果league_id不是主鍵意味着........這是不可能的使內部連接...給我三個表結構.. – 2012-01-29 16:36:25