简体   繁体   中英

Get entry by entry

I have the following scenario:

Articles Table

id | description | supplierID
_____________________________
1  | Testarticle | 1

Supplier Table

id | description 
_______________________
1  | Example Industries

When reading out an article, for example SELECT * FROM articles WHERE ID=1 , i also need the supplier description in my result.

What would be an appropriate way to achieve this?

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

Try to Join these two table

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

Check out how INNER JOIN works.

you need to join Both tables,

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

To learn more about joins, here's a great reference for it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM