如何在sql中创建INNER JOIN多个表
我有 3 个表:产品、供应商和价格。 Prices 将product_id 和vendor_id 作为外键。现在我想将价格显示为:
price_id:product_name:vendor_name:price
类似:
SELECT p.product, v.vendor, pc.price
FROM Products AS p,
Vendors AS v
INNER JOIN Prices AS pc
ON p.product_id = pc.product_id
INNER JOIN Prices AS pc
ON v.vendor = pc.vendor_id
但我没有成功。
I have 3 tables: Products, Vendors and Prices. Prices has product_id and vendor_id as foreign keys. Now i want to show Prices as:
price_id:product_name:vendor_name:price
Something like:
SELECT p.product, v.vendor, pc.price
FROM Products AS p,
Vendors AS v
INNER JOIN Prices AS pc
ON p.product_id = pc.product_id
INNER JOIN Prices AS pc
ON v.vendor = pc.vendor_id
but I didnt get it work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
Try this:
您不能使用同一别名两次
。您只能使用 pc 一次。
You can't use the same alias twice
You can only use pc once.
或者编写 3 个不同的 select 语句并用 UNION 将它们连接起来
or write 3 diffent select statements and join them with UNION
你好,我有 3 个不同的表,这个查询运行良好。
尝试根据自己的要求这样做。
Hello I have 3 different tables, and this query works well.
try to do that for your own requirement.