0

我有三个表是问题。类别、词汇和文本。我试图弄清楚如何在我的查询中加入多个连接,我想你可以添加任意数量的连接,只要你正确引用它们。

因此,以下两个可以完美地单独工作:

1.

SELECT 
categories.ID AS ID,
categories.ParentID AS ID,
vocabulary.value AS Name
FROM categories
INNER JOIN vocabulary
ON categories.sid=vocabulary.sid
WHERE vocabulary.langid=1

2.

SELECT 
categories.ID AS ID,
categories.ParentID AS ID,
tex.value AS Description
FROM categories
INNER JOIN tex
ON categories.tid=tex.tid
WHERE tex.langid=1

但是,如果我尝试按如下方式组合它们,它就不起作用。

categories.ID AS ID,
categories.ParentID AS ID,
vocabulary.value AS Name
tex.value AS Description
FROM categories
INNER JOIN tex
ON categories.tid=tex.tid
WHERE tex.langid=1

INNER JOIN vocabulary
ON categories.sid=vocabulary.sid
WHERE vocabulary.langid=1

有任何想法吗?

提前感谢约翰

4

1 回答 1

1

MySQL中,当您有同名的列时,只会显示其中之一。您需要通过提供唯一标识它们ALIAS。您可以将条件放在ON子句或WHERE子句上,因为它使用INNER JOIN.

SELECT  categories.ID AS CategoryID,
        categories.ParentID AS CategoryParentID,
        vocabulary.value AS Name
        tex.value AS Description
FROM    categories
        INNER JOIN tex
            ON categories.tid = tex.tid
        INNER JOIN vocabulary
            ON categories.sid = vocabulary.sid
WHERE   vocabulary.langid = 1 AND 
        tex.langid = 1
于 2013-09-28T18:19:04.913 回答