简体   繁体   English

关于我的关系数据库查询的建议

[英]Advice on my relational database query

Hi I have just started using relational databases at college and I am having trouble with queries when using multiple tables.嗨,我刚刚在大学开始使用关系数据库,在使用多个表时遇到查询问题。 I normalized some data to the best of my knowledge as you can see below, however I am unsure how to write a query which will show me all of the products a particular customer has bought.我尽我所知对一些数据进行了标准化,如下所示,但是我不确定如何编写一个查询来显示特定客户购买的所有产品。 When I have tried it just shows me all products along with that 1 customer even if they have not bought anything.当我尝试时,它只会向我显示所有产品以及该 1 位客户,即使他们没有购买任何东西。 Many thanks in advance!提前谢谢了!

我的表之间的关系

ps I have looked for online documentation and vids on how to create multiple table queries but all I have found involve using one table. ps 我已经查找了有关如何创建多个表查询的在线文档和视频,但我发现的所有内容都涉及使用一个表。 If anyone can point me in the direction of a good source to learn this I would appreciate it!如果有人能指出我学习这一点的好来源,我将不胜感激! Thanks again.再次感谢。

It's only a simple inner join with the related table这只是与相关表的简单内连接

select d.product_id, d.product_name
from invoce as a
inner join order as b on a.order_no = b.order_no
inner join customer as c on a.cust_no = c.cust_no
inner join product as d on b.product_id = d.product_id

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

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