Multiple joins in MySQL table

前端 未结 1 1340
误落风尘
误落风尘 2021-01-25 07:22

If I have one table that references the names of sponsors and the product ids of the products they recommend, as such:

--------------------------------
|Name |Pr         


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-25 07:52

    Join twice.

    SELECT s.name, p1.ProductName AS product_1_name, p1.ProductPrice AS product_1_price, p2.ProductName AS product_2_name, p2.ProductPrice AS product_2_price
    FROM sponsers AS s
    JOIN products AS p1 ON s.ProductID1 = p1.ProductID
    JOIN products AS p2 ON s.ProductID2 = p2.ProductID
    

    0 讨论(0)
提交回复
热议问题