2

我有以下情况:

文章表

id | description | supplierID
_____________________________
1  | Testarticle | 1

供应商表

id | description 
_______________________
1  | Example Industries

例如,在阅读文章时 SELECT * FROM articles WHERE ID=1,我还需要结果中的供应商描述。

什么是实现这一目标的合适方法?

4

3 回答 3

5
select a.id as ArticleID, a.description as ArticleDescription, a.SupplierID,
s.description as SupplierDescription
from articles a
inner join supplier s on a.supplierID = s.supplierID
where a.id = 1
于 2013-01-19T17:08:59.753 回答
2

尝试加入这两个表

SELECT  a.*, b.*
FROM    articles a
INNER JOIN Supplier b
ON a.SupplierID = b.id
WHERE   a.id = 1

看看是如何INNER JOIN工作的。

于 2013-01-19T17:08:49.133 回答
1

你需要加入两个表,

SELECT  a.*, b.*
FROM    articles a
        INNER JOIN Supplier b
            ON a.SupplierID = b.ID
WHERE   a.ID = 1

要了解有关联接的更多信息,这里有一个很好的参考

于 2013-01-19T17:07:50.530 回答