简体   繁体   English

SQL连接多个表错误

[英]SQL joining multiple tables error

I am trying to do an SQL query that will take details from different tables. 我试图做一个SQL查询,它将从不同的表中获取详细信息。

EG 例如

Products { ID, Title, Description, Price}
Offering { ID, ProductId, Price, UserID, Condition}
User     { ID, Username, etc}

I would like it so that it displays returns all the offerings of a specific product. 我希望它能显示返回特定产品的所有产品。 Each product can have multiple offerings. 每个产品可以有多个产品。 And a user can place an offering. 用户可以放置商品。 (An offering is when someone lists their own item to sell) For example the product would be a Harry Potter Book, any user can list there copy of the book for sale as an offering. (产品是某人列出自己要出售的物品时),例如,该产品为《哈利波特书》,任何用户都可以在此处列出该书的副本作为产品。

$offering = mysqli_query($con, SELECT offering.price, offering.comment, offering.productid, user.username
FROM offering
INNER JOIN username on (offering.userid=offering.userid)
WHERE offering.productid = $productid );

This should return each offering back as a row with the username of the user that has placed the offering. 这应将每个产品与放置该产品的用户的用户名作为一行返回。

At the moment it is returning multiple rows of the same offering each time display the offering with a different userid. 此刻,每次显示具有不同用户ID的产品时,它将返回同一产品的多行。

I am not sure if I have explained it properly! 我不确定我是否解释正确!

$offering = mysqli_query($con, "SELECT offering.price, offering.comment,
offering.productid, user.username from offering,user where user.ID=offering.UserID;");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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