SELECT * FROM table,用他们的名字替换FK

时间:2010-12-03 22:19:47

标签: sql mysql select

我有2个表,产品有主键和名称,价格有pk,fk(pk of product)和价格。现在我必须select * from price,但需要显示产品名称而不是fk。我怎么能这样做?

2 个答案:

答案 0 :(得分:3)

SELECT pd.name, pc.price
    FROM product AS pd
        INNER JOIN price AS pc
            ON pd.id = pc.productid

答案 1 :(得分:2)

你可以这样做:

Select p.*, pr.Name from price as p
join product as pr on p.productid = pr.Id