如何INNER加入两个以上的类别?

时间:2012-01-28 06:53:04

标签: php mysql left-join inner-join categories

我在这里有点困惑,需要一些帮助...

情况是我已经制作了三个表(fr_Leagues,fr_nations和fr_confeds),我想要做的就是添加一个联盟,它显示的类别名称不是i.d with pagination。这是代码:

现在已经固定!

  "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"

2 个答案:

答案 0 :(得分:3)

您缺少如何将不同的表链接在一起。在每个INNER JOIN上,您需要拥有它:

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

答案 1 :(得分:0)

使用此查询

SELECT * FROM fr_confeds as A

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

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

LIMIT $ paginate-&gt; start,$ paginate-&gt; limit